Skip to content

Commit

Permalink
Remove cached schema entry when creating table
Browse files Browse the repository at this point in the history
This fixes some corner cases, such as using raw SQL to drop a table
or dropping a table in another process.  However, it's safe as any
time create_table succeeds, any previous cached schema entry is
probably invalid.
  • Loading branch information
jeremyevans committed May 25, 2010
1 parent 7826985 commit aa115b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/sequel/database/schema_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def alter_table(name, generator=nil, &block)
#
# See Schema::Generator and the {"Migrations and Schema Modification" guide}[link:files/doc/migration_rdoc.html].
def create_table(name, options={}, &block)
remove_cached_schema(name)
options = {:generator=>options} if options.is_a?(Schema::Generator)
generator = options[:generator] || Schema::Generator.new(self, &block)
create_table_from_generator(name, generator, options)
Expand Down
6 changes: 6 additions & 0 deletions spec/core/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
proc{@db.create_table(:cats.as(:c)) {}}.should raise_error(Sequel::Error)
end

specify "should remove cached schema entry" do
@db.instance_variable_set(:@schemas, {'cats'=>[]})
@db.create_table(:cats){Integer :a}
@db.instance_variable_get(:@schemas).should be_empty
end

specify "should accept multiple columns" do
@db.create_table(:cats) do
column :id, :integer
Expand Down

0 comments on commit aa115b3

Please sign in to comment.