From 786a9bed2aaa178a9c772cfdcf0ff8d27d72bce1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 5 Apr 2011 14:21:03 +0300 Subject: [PATCH 1/2] postgres fix --- lib/also_migrate/migrator.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/also_migrate/migrator.rb b/lib/also_migrate/migrator.rb index bb59ae3..625e136 100644 --- a/lib/also_migrate/migrator.rb +++ b/lib/also_migrate/migrator.rb @@ -64,9 +64,12 @@ def create_tables(config) (#{col_string}) SQL else + # Postgres fix + # "CREATE TABLE XXX LIKE YYY" is invalid + # "CREATE TABLE XXX ( LIKE YYY )" is a correct one connection.execute(<<-SQL) CREATE TABLE #{new_table} - LIKE #{config[:source]}; + (LIKE #{config[:source]}); SQL end end @@ -96,4 +99,4 @@ def create_tables(config) end end end -end \ No newline at end of file +end From 8d1f0411c684f07289a9d16f1997abc4a2a801c9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 5 Apr 2011 16:41:37 +0300 Subject: [PATCH 2/2] pkey fix --- lib/also_migrate/migrator.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/also_migrate/migrator.rb b/lib/also_migrate/migrator.rb index 625e136..63e0a19 100644 --- a/lib/also_migrate/migrator.rb +++ b/lib/also_migrate/migrator.rb @@ -63,13 +63,20 @@ 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 - # Postgres fix - # "CREATE TABLE XXX LIKE YYY" is invalid - # "CREATE TABLE XXX ( LIKE YYY )" is a correct one connection.execute(<<-SQL) CREATE TABLE #{new_table} - (LIKE #{config[:source]}); + LIKE #{config[:source]}; SQL end end