tasks/database.rake in rubyrep-1.0.2 vs tasks/database.rake in rubyrep-1.0.3
- old
+ new
@@ -2,10 +2,11 @@
require 'rake'
require 'rubyrep'
require File.dirname(__FILE__) + '/task_helper.rb'
require File.dirname(__FILE__) + '/../config/test_config'
+require File.dirname(__FILE__) + '/../spec/spec_helper'
# Creates the databases for the given configuration hash
def create_database(config)
begin
RR::ConnectionExtenders.db_connect(config)
@@ -95,11 +96,11 @@
# Drops the schema and tables that were created for the postgres schema test
def drop_postgres_schema(config)
return unless config[:adapter] == 'postgresql'
ActiveRecord::Base.establish_connection config
ActiveRecord::Schema.define do
- execute "drop schema rr cascade"
+ execute "drop schema rr cascade" rescue nil
end
end
# Creates the sample schema in the database specified by the given
# configuration.
@@ -250,10 +251,22 @@
create_table :sequence_test do |t|
t.column :name, :string
end
+ create_table STRANGE_TABLE do |t|
+ t.column :first_fk, :integer
+ t.column :second_fk, :integer
+ t.column STRANGE_COLUMN, :string
+ end
+
+ ActiveRecord::Base.connection.execute(<<-end_sql)
+ ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(STRANGE_TABLE)} ADD CONSTRAINT strange_table_fkey
+ FOREIGN KEY (first_fk, second_fk)
+ REFERENCES referenced_table(first_id, second_id)
+ end_sql
+
create_table :left_table do |t|
t.column :name, :string
end if database == :left
create_table :right_table do |t|
@@ -265,14 +278,14 @@
# Removes all tables from the sample scheme
# config: Hash of configuration values for the desired database connection
def drop_sample_schema(config)
drop_postgres_schema config
- connection = RR::ConnectionExtenders.db_connect(config)
- ActiveRecord::Base.connection = connection
+ ActiveRecord::Base.establish_connection config
ActiveRecord::Schema.define do
+ 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
drop_table :extender_inverted_combined_key rescue nil
@@ -283,10 +296,11 @@
drop_table :referencing_table rescue nil
drop_table :referenced_table rescue nil
drop_table :referenced_table2 rescue nil
drop_table :table_with_manual_key
drop_table :rr_pending_changes rescue nil
+ drop_table :rr_logged_events rescue nil
drop_table :rr_running_flags rescue nil
drop_table :trigger_test rescue nil
drop_table :sequence_test rescue nil
drop_table :left_table rescue nil
drop_table :right_table rescue nil
@@ -410,11 +424,11 @@
desc "Rebuilds the test databases & schemas"
task :rebuild => [:drop_schema, :drop, :create, :create_schema, :populate]
desc "Create the sample schemas"
task :create_schema do
- create_sample_schema :left, RR::Initializer.configuration rescue nil
+ create_sample_schema :left, RR::Initializer.configuration
create_sample_schema :right, RR::Initializer.configuration rescue nil
end
desc "Writes the sample data"
task :populate do
@@ -430,11 +444,11 @@
# exits, it's database connections die.
pid = Process.fork
if pid
Process.wait pid
else
- drop_sample_schema RR::Initializer.configuration.left rescue nil
- drop_sample_schema RR::Initializer.configuration.right rescue nil
+ drop_sample_schema RR::Initializer.configuration.left
+ drop_sample_schema RR::Initializer.configuration.right
Kernel.exit!
end
end
end
end
\ No newline at end of file