Make create_table with :foreign option reversible on PostgreSQL
authorJeremy Evans <code@jeremyevans.net>
Wed, 1 Oct 2014 18:28:43 +0000 (11:28 -0700)
committerJeremy Evans <code@jeremyevans.net>
Wed, 1 Oct 2014 18:28:43 +0000 (11:28 -0700)
Now that we support dropping foreign tables, creating foreign
tables should be reversible.

CHANGELOG
lib/sequel/extensions/migration.rb
spec/adapters/postgres_spec.rb
spec/extensions/migration_spec.rb

index df36cb721325cdc05929308d94878b97ca2d50a7..e63973176e6d8b292a7384b9d0d8666ef01e42c8 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,9 @@
+=== HEAD
+
+* Make create_table with :foreign option reversible on PostgreSQL (jeremyevans)
+
+* Make drop_table with :foreign option on PostgreSQL drop a foreign table (johnnyt) (#892)
+
 === 4.15.0 (2014-10-01)
 
 * Make AssociationReflection#reciprocal not raise error if associated class contains association with invalid associated class (jeremyevans)
index 61ff6ae3a913d97ce993de3bb62cb23c8f92ca36..5457f676ec8acfe0bbb2bfc76940a8797d4db364 100644 (file)
@@ -203,12 +203,12 @@ module Sequel
       @actions << [:drop_join_table, *args]
     end
 
-    def create_table(*args)
-      @actions << [:drop_table, args.first]
+    def create_table(name, opts=OPTS)
+      @actions << [:drop_table, name, opts]
     end
 
-    def create_view(name, _, options={})
-      @actions << [:drop_view, name, options]
+    def create_view(name, _, opts=OPTS)
+      @actions << [:drop_view, name, opts]
     end
 
     def rename_column(table, name, new_name)
index 3680d5831c959d693788cae661ee9db8c48fb449..33d826bfac0f874746b910b066b63e0febbad413 100644 (file)
@@ -279,11 +279,8 @@ describe "A PostgreSQL database" do
 
   # These only test the SQL created, because a true test using file_fdw or postgres_fdw
   # requires superuser permissions, and you should not be running the tests as a superuser.
-  specify "should support creating foreign tables" do
-    DB.send(:create_table_sql, :t, DB.send(:create_table_generator){Integer :a}, :foreign=>:f, :options=>{:o=>1}).should == 'CREATE FOREIGN TABLE "t" ("a" integer) SERVER "f" OPTIONS (o \'1\')'
-  end
-
-  specify "should support dropping foreign tables" do
+  specify "should support creating and dropping foreign tables" do
+    DB.send(:create_table_sql, :t, DB.create_table_generator{Integer :a}, :foreign=>:f, :options=>{:o=>1}).should == 'CREATE FOREIGN TABLE "t" ("a" integer) SERVER "f" OPTIONS (o \'1\')'
     DB.send(:drop_table_sql, :t, :foreign=>true).should == 'DROP FOREIGN TABLE "t"'
   end
 end
index 9e080a8c21a8afa20cfa83aff23d54e55805b76b..8e3a8493eee11eaeceb130262b692c93e5854f5c 100644 (file)
@@ -121,7 +121,7 @@ describe "Reversible Migrations with Sequel.migration{change{}}" do
     end
     @db = @c.new
     @p = Proc.new do
-      create_table(:a){Integer :a}
+      create_table(:a, :foo=>:bar){Integer :a}
       add_column :a, :b, String
       add_index :a, :b
       rename_column :a, :b, :c
@@ -146,7 +146,7 @@ describe "Reversible Migrations with Sequel.migration{change{}}" do
   specify "should apply up with normal actions in normal order" do
     p = @p
     Sequel.migration{change(&p)}.apply(@db, :up)
-    @db.actions.should == [[:create_table, :a],
+    @db.actions.should == [[:create_table, :a, {:foo=>:bar}],
       [:add_column, :a, :b, String],
       [:add_index, :a, :b],
       [:rename_column, :a, :b, :c],
@@ -189,7 +189,7 @@ describe "Reversible Migrations with Sequel.migration{change{}}" do
       [:rename_column, :a, :c, :b],
       [:drop_index, :a, :b],
       [:drop_column, :a, :b],
-      [:drop_table, :a]]
+      [:drop_table, :a, {:foo=>:bar}]]
   end
   
   specify "should raise in the down direction if migration uses unsupported method" do