aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib/af83/cloning
diff options
context:
space:
mode:
authorRobert2017-06-08 10:51:27 +0200
committerRobert2017-06-08 10:51:27 +0200
commit38e5a5329541a54f98d771c3aa252b91b823b94f (patch)
treed99a9223a7c58d0c029f6401bde9a2aa69da98bb /spec/lib/af83/cloning
parent15b7cf8213d730fa36740a74bc75baa5fc56dd62 (diff)
downloadchouette-core-38e5a5329541a54f98d771c3aa252b91b823b94f.tar.bz2
Refs: #3604 @2h checking sequences as defaults
Diffstat (limited to 'spec/lib/af83/cloning')
-rw-r--r--spec/lib/af83/cloning/clone_schema_spec.rb151
1 files changed, 45 insertions, 106 deletions
diff --git a/spec/lib/af83/cloning/clone_schema_spec.rb b/spec/lib/af83/cloning/clone_schema_spec.rb
index aa74bb372..5e441cc8e 100644
--- a/spec/lib/af83/cloning/clone_schema_spec.rb
+++ b/spec/lib/af83/cloning/clone_schema_spec.rb
@@ -1,135 +1,69 @@
-include Support::PGCatalog
-
-RSpec.describe AF83::SchemaCloner do
+RSpec.describe AF83::SchemaCloner, type: :pg_catalog do
let( :source_schema ){ "source_schema" }
let( :target_schema ){ "target_schema" }
let( :child_table ){ "children" }
let( :parent_table ){ "parents" }
- subject { described_class.new }
-
- before do
- create_schema_with_tables
- end
+ subject { described_class.new source_schema, target_schema }
- context "before cloning" do
- it "target schema does not exist" do
- expect( get_schema_oid(target_schema) ).to be_nil
+ context "after cloning" do
+ before do
+ create_schema_with_tables
+ subject.clone_schema
end
- end
-
- shared_examples_for "after cloning schema" do
- let( :expected_target_parent_count ){ include_recs ? 1 : 0 }
- let( :expected_target_child_count ){ include_recs ? 1 : 0 }
-
- it "table information is correctly read" do
+ it "table information is correctly duplicated" do
+ expect_same_sequence_params("#{child_table}_id_seq")
+ expect_same_sequence_params("#{parent_table}_id_seq")
expect(get_table_information(source_schema, child_table))
.to eq([{"table_schema"=>"source_schema",
- "table_name"=>"children",
- "table_type"=>"BASE TABLE",
- "self_referencing_column_name"=>nil,
- "reference_generation"=>nil,
- "user_defined_type_catalog"=>nil,
- "user_defined_type_schema"=>nil,
- "user_defined_type_name"=>nil,
- "is_insertable_into"=>"YES",
- "is_typed"=>"NO",
- "commit_action"=>nil}])
+ "table_name"=>"children",
+ "table_type"=>"BASE TABLE",
+ "self_referencing_column_name"=>nil,
+ "reference_generation"=>nil,
+ "user_defined_type_catalog"=>nil,
+ "user_defined_type_schema"=>nil,
+ "user_defined_type_name"=>nil,
+ "is_insertable_into"=>"YES",
+ "is_typed"=>"NO",
+ "commit_action"=>nil}])
expect( get_table_information(target_schema, child_table))
.to eq([{"table_schema"=>"target_schema",
- "table_name"=>"children",
- "table_type"=>"BASE TABLE",
- "self_referencing_column_name"=>nil,
- "reference_generation"=>nil,
- "user_defined_type_catalog"=>nil,
- "user_defined_type_schema"=>nil,
- "user_defined_type_name"=>nil,
- "is_insertable_into"=>"YES",
- "is_typed"=>"NO",
- "commit_action"=>nil}])
+ "table_name"=>"children",
+ "table_type"=>"BASE TABLE",
+ "self_referencing_column_name"=>nil,
+ "reference_generation"=>nil,
+ "user_defined_type_catalog"=>nil,
+ "user_defined_type_schema"=>nil,
+ "user_defined_type_name"=>nil,
+ "is_insertable_into"=>"YES",
+ "is_typed"=>"NO",
+ "commit_action"=>nil}])
end
-
- it "has the correct sequences" do
- expect(get_sequences(target_schema, child_table))
- .to eq([{"sequence_name"=>"#{child_table}_id_seq",
- "last_value"=>"1",
- "start_value"=>"1",
- "increment_by"=>"1",
- "max_value"=>"9223372036854775807",
- "min_value"=>"1",
- "cache_value"=>"1",
- "log_cnt"=>"0",
- "is_cycled"=>"f",
- "is_called"=>"f"}])
- expect(get_sequences(target_schema, parent_table))
- .to eq([{"sequence_name"=>"#{parent_table}_id_seq",
- "last_value"=>"1",
- "start_value"=>"1",
- "increment_by"=>"1",
- "max_value"=>"9223372036854775807",
- "min_value"=>"1",
- "cache_value"=>"1",
- "log_cnt"=>"0",
- "is_cycled"=>"f",
- "is_called"=>"f"}])
- end
- it "has the correct foreign keys" do
+ xit "has the correct foreign keys" do
expect( get_foreign_keys(target_schema, child_table) )
- .to eq([{
+ .to eq([{
"constraint_name" => "children_parents",
"constraint_def" => "FOREIGN KEY (parents_id) REFERENCES target_schema.parents(id)"}])
end
- it "the data has been copied or not" do
- source_pt_count = count_records(source_schema, parent_table)
- source_ch_count = count_records(source_schema, child_table)
- target_pt_count = count_records(target_schema, parent_table)
- target_ch_count = count_records(target_schema, child_table)
-
- expect( source_pt_count ).to eq( 1 )
- expect( source_ch_count ).to eq( 1 )
- expect( target_pt_count ).to eq( expected_target_parent_count )
- expect( target_ch_count ).to eq( expected_target_child_count )
+ xit "the data has been copied" do
end
- end
- context "step by step", :wip do
- # before do
- # subject.clone_schema(source_schema, target_schema)
- # end
- it "assure target schema nonexistance" do
- expect{ subject.clone_schema(source_schema, source_schema) }.to raise_error(RuntimeError)
- end
- it "assure source schema's existance" do
- expect{ subject.clone_schema(target_schema, target_schema) }.to raise_error(RuntimeError)
- end
-
- end
-
- context "after cloning" do
- before do
- subject.clone_schema(source_schema, target_schema, include_recs: include_recs)
+ xit "it has the correct unique keys"
+
end
- context "without including records" do
- let( :include_recs ){ false }
- it_behaves_like 'after cloning schema'
+ xit "inserts are independent" do
end
- context "with including records" do
- let( :include_recs ){ true }
- it_behaves_like 'after cloning schema'
- end
end
-end
-
-def create_schema_with_tables
- execute <<-EOSQL
+ def create_schema_with_tables
+ execute <<-EOSQL
DROP SCHEMA IF EXISTS #{source_schema} CASCADE;
CREATE SCHEMA #{source_schema};
@@ -138,13 +72,18 @@ def create_schema_with_tables
);
CREATE TABLE #{source_schema}.#{child_table} (
id bigserial PRIMARY KEY,
- #{parent_table}_id bigint
+ #{parent_table}_id bigint,
+ some_key bigint NOT NULL,
+ is_orphan boolean DEFAULT false
);
+
+ CREATE UNIQUE INDEX #{source_schema}.#{child_table}_some_key_idx ON #{source_schema}.#{child_table} (some_key);
+
ALTER TABLE #{source_schema}.#{child_table}
ADD CONSTRAINT #{child_table}_#{parent_table}
FOREIGN KEY( #{parent_table}_id ) REFERENCES #{source_schema}.#{parent_table}(id);
INSERT INTO #{source_schema}.#{parent_table} VALUES (100);
INSERT INTO #{source_schema}.#{child_table} VALUES (1, 100);
- EOSQL
+ EOSQL
+ end
end
-