Permalink
Browse files

Add Database#global_index_namespace? method

This checks if the index namespace is global, or whether there is
a separate index namespace per table.  The default is true since
that is what most databases seem to use, with MySQL, MSSQL, and
Oracle being exceptions.

It's a shame this wasn't here in the beginning, since this
should be used by the default_index_name method to omit the
table name if indexes are already namespaced per table.  For
backward compatibility, that unfortunately cannot be done.
  • Loading branch information...
1 parent bce108b commit 932b11828ce44f75165f0801003453906b19b2d3 @jeremyevans committed May 30, 2012
@@ -28,6 +28,11 @@ def database_type
:mssql
end
+ # Microsoft SQL Server namespaces indexes per table.
+ def global_index_namespace?
+ false
+ end
+
# Use the system tables to get index information
def indexes(table, opts={})
m = output_identifier_meth
@@ -76,6 +76,11 @@ def foreign_key_list(table, opts={})
h.values
end
+ # MySQL namespaces indexes per table.
+ def global_index_namespace?
+ false
+ end
+
# Use SHOW INDEX FROM to get the index information for the
# table.
#
@@ -29,6 +29,11 @@ def database_type
:oracle
end
+ # Oracle namespaces indexes per table.
+ def global_index_namespace?
+ false
+ end
+
def tables(opts={})
m = output_identifier_meth
metadata_dataset.from(:tab).server(opts[:server]).select(:tname).filter(:tabtype => 'TABLE').map{|r| m.call(r[:tname])}
@@ -114,6 +114,12 @@ def from_application_timestamp(v)
Sequel.convert_output_timestamp(v, timezone)
end
+ # Whether the database uses a global namespace for the index. If
+ # false, the indexes are going to be namespaced per table.
+ def global_index_namespace?
+ true
+ end
+
# Return true if already in a transaction given the options,
# false otherwise. Respects the :server option for selecting
# a shard.
@@ -1996,6 +1996,12 @@ def @db.dc; @dc end
end
end
+describe "Database#global_index_namespace?" do
+ specify "should be true by default" do
+ Sequel::Database.new.global_index_namespace?.should == true
+ end
+end
+
describe "Database#supports_savepoints?" do
specify "should be false by default" do
Sequel::Database.new.supports_savepoints?.should == false

0 comments on commit 932b118

Please sign in to comment.