tasks/database.rake in rubyrep-1.0.4 vs tasks/database.rake in rubyrep-1.0.5

- old
+ new

@@ -88,10 +88,14 @@ end_sql create_table :rr_sequence_test do |t| t.column :name, :string end + + create_table :rr_duplicate do |t| + t.column :name, :string + end end end # Drops the schema and tables that were created for the postgres schema test def drop_postgres_schema(config) @@ -270,10 +274,37 @@ end if database == :left create_table :right_table do |t| t.column :name, :string end if database == :right + + if config.send(database)[:adapter] == 'postgresql' + create_table :rr_duplicate, :id => false do |t| + t.column :blub, :string + end rescue nil + + ActiveRecord::Base.connection.execute(<<-end_sql) rescue nil + ALTER TABLE rr_duplicate ADD COLUMN key SERIAL + end_sql + + ActiveRecord::Base.connection.execute(<<-end_sql) rescue nil + ALTER TABLE rr_duplicate ADD CONSTRAINT rr_duplicate_pkey + PRIMARY KEY (key) + end_sql + + # duplicate that should *not* be found during PostgreSQL schema support tests + create_table :rr_referencing do |t| + t.column :first_fk, :integer + t.column :second_fk, :integer + end rescue nil + + ActiveRecord::Base.connection.execute(<<-end_sql) + ALTER TABLE rr_referencing ADD CONSTRAINT rr_referencing_fkey + FOREIGN KEY (first_fk, second_fk) + REFERENCES referenced_table(first_id, second_id) + end_sql + end end end # Removes all tables from the sample scheme # config: Hash of configuration values for the desired database connection @@ -281,10 +312,12 @@ drop_postgres_schema config ActiveRecord::Base.establish_connection config ActiveRecord::Schema.define do + drop_table :rr_referencing rescue nil + drop_table :rr_duplicate rescue nil drop_table STRANGE_TABLE rescue nil drop_table :extender_type_check rescue nil drop_table :extender_no_record rescue nil drop_table :extender_one_record rescue nil drop_table :extender_without_key rescue nil @@ -378,9 +411,16 @@ {:first_id => 1, :second_id => 1, :name => 'aa'}, {:first_id => 1, :second_id => 2, :name => 'ab'}, {:first_id => 2, :second_id => 1, :name => 'ba'}, {:first_id => 3, :second_id => 1} ].each { |row| create_row connection, 'extender_combined_key', row} + + connection.execute("delete from referenced_table") + connection.execute("delete from referencing_table") + create_row connection, 'referenced_table', { + :first_id => 1, :second_id => 2, :name => 'bla' + } + create_row connection, 'referencing_table', {:first_fk => 1, :second_fk => 2} end # Reinitializes the sample schema with the sample data def create_sample_data # Create records existing in both databases \ No newline at end of file