diff --git a/lib/also_migrate/migrator.rb b/lib/also_migrate/migrator.rb index bb59ae3..63e0a19 100644 --- a/lib/also_migrate/migrator.rb +++ b/lib/also_migrate/migrator.rb @@ -63,6 +63,16 @@ def create_tables(config) CREATE TABLE #{new_table} (#{col_string}) SQL + elsif connection.class.to_s.include?('PostgreSQL') + # Postgres patch + # 1. Valid table creation + # "CREATE TABLE XXX LIKE YYY" is invalid + # "CREATE TABLE XXX ( LIKE YYY )" is a correct one + # 2. Add primary key to new table + connection.execute(<<-SQL) + CREATE TABLE #{new_table} + (LIKE #{config[:source]} INCLUDING INDEXES); + SQL else connection.execute(<<-SQL) CREATE TABLE #{new_table} @@ -96,4 +106,4 @@ def create_tables(config) end end end -end \ No newline at end of file +end