dbagile 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENCE.textile +12 -0
- data/README.textile +89 -0
- data/bin/dba +22 -0
- data/lib/dbagile/adapter/sequel/class_methods.rb +18 -0
- data/lib/dbagile/adapter/sequel/connection.rb +38 -0
- data/lib/dbagile/adapter/sequel/data/table_driven.rb +30 -0
- data/lib/dbagile/adapter/sequel/data/transaction_driven.rb +43 -0
- data/lib/dbagile/adapter/sequel/schema/concrete_script.rb +135 -0
- data/lib/dbagile/adapter/sequel/schema/physical_dump.rb +106 -0
- data/lib/dbagile/adapter/sequel/schema/schema2sequel_args.rb +71 -0
- data/lib/dbagile/adapter/sequel/schema/table_driven.rb +52 -0
- data/lib/dbagile/adapter/sequel/schema/transaction_driven.rb +46 -0
- data/lib/dbagile/adapter/sequel/sequel_tracer.rb +144 -0
- data/lib/dbagile/adapter/sequel.rb +46 -0
- data/lib/dbagile/adapter.rb +15 -0
- data/lib/dbagile/command/api.rb +49 -0
- data/lib/dbagile/command/bulk/commons.rb +130 -0
- data/lib/dbagile/command/bulk/export.rb +99 -0
- data/lib/dbagile/command/bulk/import.rb +147 -0
- data/lib/dbagile/command/bulk.rb +3 -0
- data/lib/dbagile/command/class_methods.rb +103 -0
- data/lib/dbagile/command/db/add.rb +94 -0
- data/lib/dbagile/command/db/list.rb +40 -0
- data/lib/dbagile/command/db/ping.rb +49 -0
- data/lib/dbagile/command/db/rm.rb +52 -0
- data/lib/dbagile/command/db/stage.rb +81 -0
- data/lib/dbagile/command/db/use.rb +48 -0
- data/lib/dbagile/command/db.rb +6 -0
- data/lib/dbagile/command/dba.rb +121 -0
- data/lib/dbagile/command/help.rb +50 -0
- data/lib/dbagile/command/repo/create.rb +54 -0
- data/lib/dbagile/command/repo.rb +1 -0
- data/lib/dbagile/command/robust.rb +86 -0
- data/lib/dbagile/command/schema/check.rb +59 -0
- data/lib/dbagile/command/schema/commons.rb +118 -0
- data/lib/dbagile/command/schema/diff.rb +101 -0
- data/lib/dbagile/command/schema/dump.rb +48 -0
- data/lib/dbagile/command/schema/merge.rb +55 -0
- data/lib/dbagile/command/schema/sql_script.rb +124 -0
- data/lib/dbagile/command/schema.rb +6 -0
- data/lib/dbagile/command/sql/drop.rb +40 -0
- data/lib/dbagile/command/sql/heading.rb +34 -0
- data/lib/dbagile/command/sql/send.rb +67 -0
- data/lib/dbagile/command/sql/show.rb +42 -0
- data/lib/dbagile/command/sql.rb +4 -0
- data/lib/dbagile/command/web/tools.rb +23 -0
- data/lib/dbagile/command/web.rb +1 -0
- data/lib/dbagile/command.rb +158 -0
- data/lib/dbagile/contract/connection.rb +66 -0
- data/lib/dbagile/contract/data/dataset.rb +69 -0
- data/lib/dbagile/contract/data/table_driven.rb +49 -0
- data/lib/dbagile/contract/data/transaction_driven.rb +74 -0
- data/lib/dbagile/contract/data.rb +3 -0
- data/lib/dbagile/contract/robust/helpers.rb +19 -0
- data/lib/dbagile/contract/robust/optimistic/data/table_driven.rb +31 -0
- data/lib/dbagile/contract/robust/optimistic/data/transaction_driven.rb +45 -0
- data/lib/dbagile/contract/robust/optimistic/schema/table_driven.rb +53 -0
- data/lib/dbagile/contract/robust/optimistic/schema/transaction_driven.rb +45 -0
- data/lib/dbagile/contract/robust/optimistic.rb +18 -0
- data/lib/dbagile/contract/robust.rb +20 -0
- data/lib/dbagile/contract/schema/table_driven.rb +89 -0
- data/lib/dbagile/contract/schema/transaction_driven.rb +68 -0
- data/lib/dbagile/contract/schema.rb +2 -0
- data/lib/dbagile/contract/utils/delegate.rb +17 -0
- data/lib/dbagile/contract/utils/full.rb +13 -0
- data/lib/dbagile/contract/utils.rb +2 -0
- data/lib/dbagile/contract.rb +5 -0
- data/lib/dbagile/core/chain.rb +92 -0
- data/lib/dbagile/core/connection.rb +51 -0
- data/lib/dbagile/core/database.rb +221 -0
- data/lib/dbagile/core/io/dsl.rb +95 -0
- data/lib/dbagile/core/io/robustness.rb +82 -0
- data/lib/dbagile/core/io.rb +2 -0
- data/lib/dbagile/core/repository/builder.rb +67 -0
- data/lib/dbagile/core/repository/yaml_methods.rb +82 -0
- data/lib/dbagile/core/repository.rb +211 -0
- data/lib/dbagile/core/schema/builder/coercion.rb +210 -0
- data/lib/dbagile/core/schema/builder/concept_factory.rb +61 -0
- data/lib/dbagile/core/schema/builder.rb +187 -0
- data/lib/dbagile/core/schema/composite.rb +239 -0
- data/lib/dbagile/core/schema/computations/filter.rb +40 -0
- data/lib/dbagile/core/schema/computations/merge.rb +55 -0
- data/lib/dbagile/core/schema/computations/minus.rb +44 -0
- data/lib/dbagile/core/schema/computations/split.rb +37 -0
- data/lib/dbagile/core/schema/computations.rb +4 -0
- data/lib/dbagile/core/schema/database_schema.rb +129 -0
- data/lib/dbagile/core/schema/errors.rb +173 -0
- data/lib/dbagile/core/schema/logical/attribute.rb +68 -0
- data/lib/dbagile/core/schema/logical/constraint/candidate_key.rb +70 -0
- data/lib/dbagile/core/schema/logical/constraint/foreign_key.rb +121 -0
- data/lib/dbagile/core/schema/logical/constraint.rb +58 -0
- data/lib/dbagile/core/schema/logical/constraints.rb +28 -0
- data/lib/dbagile/core/schema/logical/heading.rb +47 -0
- data/lib/dbagile/core/schema/logical/relvar.rb +81 -0
- data/lib/dbagile/core/schema/logical.rb +24 -0
- data/lib/dbagile/core/schema/migrate/abstract_script.rb +35 -0
- data/lib/dbagile/core/schema/migrate/collapse_table.rb +15 -0
- data/lib/dbagile/core/schema/migrate/create_table.rb +15 -0
- data/lib/dbagile/core/schema/migrate/drop_table.rb +15 -0
- data/lib/dbagile/core/schema/migrate/expand_table.rb +15 -0
- data/lib/dbagile/core/schema/migrate/operation.rb +141 -0
- data/lib/dbagile/core/schema/migrate/stager.rb +282 -0
- data/lib/dbagile/core/schema/migrate.rb +2 -0
- data/lib/dbagile/core/schema/part.rb +114 -0
- data/lib/dbagile/core/schema/physical/index.rb +64 -0
- data/lib/dbagile/core/schema/physical/indexes.rb +12 -0
- data/lib/dbagile/core/schema/physical.rb +26 -0
- data/lib/dbagile/core/schema/robustness.rb +39 -0
- data/lib/dbagile/core/schema/schema_object.rb +94 -0
- data/lib/dbagile/core/schema.rb +254 -0
- data/lib/dbagile/core/transaction.rb +74 -0
- data/lib/dbagile/core.rb +7 -0
- data/lib/dbagile/environment/buffering.rb +45 -0
- data/lib/dbagile/environment/delegator.rb +59 -0
- data/lib/dbagile/environment/interactions.rb +208 -0
- data/lib/dbagile/environment/on_error.rb +47 -0
- data/lib/dbagile/environment/repository.rb +161 -0
- data/lib/dbagile/environment/robustness.rb +7 -0
- data/lib/dbagile/environment/testing.rb +23 -0
- data/lib/dbagile/environment.rb +122 -0
- data/lib/dbagile/errors.rb +30 -0
- data/lib/dbagile/io/csv.rb +99 -0
- data/lib/dbagile/io/json.rb +41 -0
- data/lib/dbagile/io/pretty_table.rb +128 -0
- data/lib/dbagile/io/ruby.rb +62 -0
- data/lib/dbagile/io/text.rb +18 -0
- data/lib/dbagile/io/type_safe.rb +65 -0
- data/lib/dbagile/io/xml.rb +35 -0
- data/lib/dbagile/io/yaml.rb +30 -0
- data/lib/dbagile/io.rb +94 -0
- data/lib/dbagile/loader.rb +16 -0
- data/lib/dbagile/plugin.rb +29 -0
- data/lib/dbagile/restful/client/delete.rb +22 -0
- data/lib/dbagile/restful/client/get.rb +24 -0
- data/lib/dbagile/restful/client/post.rb +22 -0
- data/lib/dbagile/restful/client/utils.rb +16 -0
- data/lib/dbagile/restful/client.rb +41 -0
- data/lib/dbagile/restful/middleware/delete.rb +22 -0
- data/lib/dbagile/restful/middleware/get.rb +27 -0
- data/lib/dbagile/restful/middleware/one_database.rb +82 -0
- data/lib/dbagile/restful/middleware/post.rb +23 -0
- data/lib/dbagile/restful/middleware/utils.rb +65 -0
- data/lib/dbagile/restful/middleware.rb +54 -0
- data/lib/dbagile/restful/server.rb +65 -0
- data/lib/dbagile/restful.rb +9 -0
- data/lib/dbagile/robustness/dependencies.rb +36 -0
- data/lib/dbagile/robustness/file_system.rb +53 -0
- data/lib/dbagile/robustness.rb +14 -0
- data/lib/dbagile/tools/file_system.rb +24 -0
- data/lib/dbagile/tools/math.rb +11 -0
- data/lib/dbagile/tools/ordered_hash.rb +39 -0
- data/lib/dbagile/tools/ruby.rb +78 -0
- data/lib/dbagile/tools/string.rb +6 -0
- data/lib/dbagile/tools/tuple.rb +49 -0
- data/lib/dbagile/tools.rb +6 -0
- data/lib/dbagile.rb +66 -0
- data/test/assumptions/equality.spec +11 -0
- data/test/assumptions/fixtures.rb +39 -0
- data/test/assumptions/inheritance.spec +17 -0
- data/test/assumptions/sequel/autonumber.spec +19 -0
- data/test/assumptions/sequel/connect.spec +29 -0
- data/test/assumptions/sequel/test.db +0 -0
- data/test/assumptions/stdlib/pathname.spec +13 -0
- data/test/assumptions/yaml/fixtures.rb +25 -0
- data/test/assumptions/yaml/to_yaml.spec +10 -0
- data/test/assumptions.spec +2 -0
- data/test/commands/bulk/export.spec +100 -0
- data/test/commands/bulk/import.spec +49 -0
- data/test/commands/db/add.spec +31 -0
- data/test/commands/db/list.spec +29 -0
- data/test/commands/db/ping.spec +21 -0
- data/test/commands/db/rm.spec +18 -0
- data/test/commands/db/use.spec +18 -0
- data/test/commands/dba.spec +54 -0
- data/test/commands/repo/create.spec +30 -0
- data/test/commands/schema/check.spec +25 -0
- data/test/commands/schema/diff.spec +30 -0
- data/test/commands/schema/dump.spec +23 -0
- data/test/commands/schema/fixtures/add_constraint.yaml +30 -0
- data/test/commands/schema/fixtures/announced.yaml +28 -0
- data/test/commands/schema/fixtures/effective.yaml +20 -0
- data/test/commands/schema/fixtures/invalid.yaml +6 -0
- data/test/commands/schema/sql_script.spec +56 -0
- data/test/commands/sql/drop.spec +25 -0
- data/test/commands/sql/heading.spec +7 -0
- data/test/commands/sql/scripts/delete.sql +1 -0
- data/test/commands/sql/scripts/insert.sql +2 -0
- data/test/commands/sql/send.spec +29 -0
- data/test/commands/sql/show.spec +17 -0
- data/test/commands.spec +138 -0
- data/test/contract/connection/transaction.ex +11 -0
- data/test/contract/connection.spec +9 -0
- data/test/contract/data/dataset/columns.ex +5 -0
- data/test/contract/data/dataset/count.ex +5 -0
- data/test/contract/data/dataset.spec +9 -0
- data/test/contract/data/table_driven/dataset.ex +31 -0
- data/test/contract/data/table_driven/exists_q.ex +27 -0
- data/test/contract/data/table_driven.spec +9 -0
- data/test/contract/data/transaction_driven/delete.ex +29 -0
- data/test/contract/data/transaction_driven/direct_sql.ex +19 -0
- data/test/contract/data/transaction_driven/insert.ex +8 -0
- data/test/contract/data/transaction_driven/update.ex +19 -0
- data/test/contract/data/transaction_driven.spec +18 -0
- data/test/contract/robust/data/table_driven.spec +15 -0
- data/test/contract/robust/data/transaction_driven.spec +21 -0
- data/test/contract/robust/schema/table_driven.spec +21 -0
- data/test/contract/robust/schema/transaction_driven.spec +19 -0
- data/test/contract/schema/table_driven/column_names.ex +5 -0
- data/test/contract/schema/table_driven/has_column_q.ex +13 -0
- data/test/contract/schema/table_driven/has_table_q.ex +11 -0
- data/test/contract/schema/table_driven/heading.ex +5 -0
- data/test/contract/schema/table_driven.spec +9 -0
- data/test/contract/schema/transaction_driven/create_table.ex +10 -0
- data/test/contract/schema/transaction_driven/drop_table.ex +10 -0
- data/test/contract/schema/transaction_driven.spec +18 -0
- data/test/contract.spec +66 -0
- data/test/fixtures/basics/data/basic_values.rb +13 -0
- data/test/fixtures/basics/data/empty_table.rb +3 -0
- data/test/fixtures/basics/data/non_empty_table.rb +4 -0
- data/test/fixtures/basics/data/parts.rb +8 -0
- data/test/fixtures/basics/data/suppliers.rb +7 -0
- data/test/fixtures/basics/data/supplies.rb +14 -0
- data/test/fixtures/basics/dbagile.idx +20 -0
- data/test/fixtures/basics/fixtures.yaml +28 -0
- data/test/fixtures/basics/robust.db +0 -0
- data/test/fixtures/basics/suppliers.yaml +30 -0
- data/test/fixtures/basics/test.db +0 -0
- data/test/fixtures/empty/dbagile.idx +5 -0
- data/test/fixtures.rb +152 -0
- data/test/restful/delete/no_format.ex +32 -0
- data/test/restful/delete.spec +8 -0
- data/test/restful/get/csv_format.ex +12 -0
- data/test/restful/get/json_format.ex +19 -0
- data/test/restful/get/query_string.ex +11 -0
- data/test/restful/get/text_format.ex +12 -0
- data/test/restful/get/yaml_format.ex +14 -0
- data/test/restful/get.spec +5 -0
- data/test/restful/post/no_format.ex +22 -0
- data/test/restful/post.spec +8 -0
- data/test/restful.spec +32 -0
- data/test/run_all_suite.rb +51 -0
- data/test/spec_helper.rb +26 -0
- data/test/support/be_a_valid_json_string.rb +19 -0
- data/test/support/be_a_valid_yaml_string.rb +18 -0
- data/test/unit/adapter/factor.spec +13 -0
- data/test/unit/adapter/sequel/new.spec +19 -0
- data/test/unit/command/api.spec +12 -0
- data/test/unit/command/command_for.spec +36 -0
- data/test/unit/command/command_name_of.spec +21 -0
- data/test/unit/command/ruby_method_for.spec +21 -0
- data/test/unit/command/sanity.spec +34 -0
- data/test/unit/contract/utils/delegate/delegate.spec +23 -0
- data/test/unit/core/chain/chain.spec +57 -0
- data/test/unit/core/chain/connect.spec +22 -0
- data/test/unit/core/chain/delegate_chain.spec +16 -0
- data/test/unit/core/chain/initialize.spec +19 -0
- data/test/unit/core/chain/plug.spec +31 -0
- data/test/unit/core/io/dsl/scope.spec +9 -0
- data/test/unit/core/repository/create_bang.spec +31 -0
- data/test/unit/core/repository/current.spec +31 -0
- data/test/unit/core/repository/database.spec +47 -0
- data/test/unit/core/repository/fixtures/corrupted/dbagile.idx +1 -0
- data/test/unit/core/repository/fixtures/test_and_prod/dbagile.idx +21 -0
- data/test/unit/core/repository/fixtures.rb +25 -0
- data/test/unit/core/repository/has_database_q.spec +16 -0
- data/test/unit/core/repository/load.spec +51 -0
- data/test/unit/core/repository/to_yaml.spec +17 -0
- data/test/unit/core/schema/check.spec +32 -0
- data/test/unit/core/schema/empty_q.spec +18 -0
- data/test/unit/core/schema/filter.spec +42 -0
- data/test/unit/core/schema/fixtures/dbagile.yaml +7 -0
- data/test/unit/core/schema/fixtures/empty.yaml +11 -0
- data/test/unit/core/schema/fixtures/invalid.yaml +54 -0
- data/test/unit/core/schema/fixtures/left.yaml +46 -0
- data/test/unit/core/schema/fixtures/left_minus_right.yaml +31 -0
- data/test/unit/core/schema/fixtures/right.yaml +46 -0
- data/test/unit/core/schema/fixtures/right_minus_left.yaml +31 -0
- data/test/unit/core/schema/fixtures/suppliers_and_parts.yaml +30 -0
- data/test/unit/core/schema/fixtures.rb +32 -0
- data/test/unit/core/schema/merge.spec +72 -0
- data/test/unit/core/schema/minus.spec +26 -0
- data/test/unit/core/schema/sanity.spec +39 -0
- data/test/unit/core/schema/split.spec +58 -0
- data/test/unit/core/schema/stage_script.spec +26 -0
- data/test/unit/core/schema/to_yaml.spec +13 -0
- data/test/unit/core/schema/yaml_display.spec +14 -0
- data/test/unit/core/schema/yaml_load.spec +20 -0
- data/test/unit/core/transaction/transaction.spec +10 -0
- data/test/unit/fixtures.rb +67 -0
- data/test/unit/io/to_xxx.spec +52 -0
- data/test/unit/plugin/options.spec +21 -0
- data/test/unit/plugin/tuple_heading.spec +11 -0
- data/test/unit/plugin/with_options.spec +12 -0
- data/test/unit/tools/ruby/class_unqualified_name.spec +26 -0
- data/test/unit/tools/ruby/extract_file_rdoc.spec +10 -0
- data/test/unit/tools/ruby/fixtures/rdoc.txt +12 -0
- data/test/unit/tools/ruby/fixtures.rb +19 -0
- data/test/unit/tools/ruby/optional_args_block_call.spec +35 -0
- data/test/unit/tools/ruby/parent_module.spec +21 -0
- data/test/unit/tools/ruby/rdoc_file_paragraphs.spec +13 -0
- data/test/unit/tools/tuple/tuple_heading.spec +11 -0
- data/test/unit/tools/tuple/tuple_key.spec +27 -0
- data/test/unit/tools/tuple/tuple_project.spec +23 -0
- data/test/unit.spec +3 -0
- metadata +422 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
shared_examples_for("The schema:dump command") do
|
|
2
|
+
|
|
3
|
+
let(:invalid){ File.expand_path('../fixtures/invalid.yaml', __FILE__) }
|
|
4
|
+
|
|
5
|
+
it "should return a Schema instance" do
|
|
6
|
+
dba.schema_dump.should be_kind_of(DbAgile::Core::Schema::DatabaseSchema)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should display the Schema as a valid YAML string" do
|
|
10
|
+
dba.output_buffer = StringIO.new
|
|
11
|
+
dba.schema_dump
|
|
12
|
+
dba.output_buffer.string.should be_a_valid_yaml_string
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should raise an error on invalid schema" do
|
|
16
|
+
lambda{ dba.schema_dump [ invalid ] }.should raise_error(DbAgile::SchemaSemanticsError)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should not raise an error on invalid schema with --no-check" do
|
|
20
|
+
lambda{ dba.schema_dump ['--no-check', invalid] }.should_not raise_error(DbAgile::SchemaSemanticsError)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
logical:
|
|
3
|
+
SUPPLIERS:
|
|
4
|
+
heading:
|
|
5
|
+
S#: { domain: Integer, mandatory: true }
|
|
6
|
+
NAME: { domain: String, mandatory: true }
|
|
7
|
+
CITY: { domain: String, mandatory: true }
|
|
8
|
+
constraints:
|
|
9
|
+
pk_suppliers: { type: :primary_key, attributes: [ 'S#' ] }
|
|
10
|
+
PARTS:
|
|
11
|
+
heading:
|
|
12
|
+
P#: { domain: Integer, mandatory: true }
|
|
13
|
+
NAME: { domain: String, mandatory: true }
|
|
14
|
+
COLOR: { domain: String, mandatory: true }
|
|
15
|
+
constraints:
|
|
16
|
+
pk_parts: { type: :primary_key, attributes: [ 'P#' ] }
|
|
17
|
+
SUPPLIES:
|
|
18
|
+
heading:
|
|
19
|
+
S#: { domain: Integer, mandatory: true }
|
|
20
|
+
P#: { domain: Integer, mandatory: true }
|
|
21
|
+
QTY: { domain: Integer, mandatory: true }
|
|
22
|
+
constraints:
|
|
23
|
+
pk_supplies: { type: :primary_key, attributes: [ 'S#', 'P#' ] }
|
|
24
|
+
is_a_known_supplier: { type: :foreign_key, attributes: [ 'S#' ], references: :SUPPLIERS }
|
|
25
|
+
is_a_known_part: { type: :foreign_key, attributes: [ 'P#' ], references: :PARTS }
|
|
26
|
+
---
|
|
27
|
+
physical:
|
|
28
|
+
indexes:
|
|
29
|
+
SUPPLIER_NAMES: { relvar: SUPPLIERS, attributes: [ 'NAME' ] }
|
|
30
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
logical:
|
|
3
|
+
SUPPLIERS:
|
|
4
|
+
heading:
|
|
5
|
+
S#: { domain: Integer, mandatory: true }
|
|
6
|
+
NAME: { domain: String, mandatory: true }
|
|
7
|
+
CITY: { domain: String, mandatory: true }
|
|
8
|
+
constraints:
|
|
9
|
+
pk_suppliers: { type: :primary_key, attributes: [ 'S#' ] }
|
|
10
|
+
PARTS:
|
|
11
|
+
heading:
|
|
12
|
+
P#: { domain: Integer, mandatory: true }
|
|
13
|
+
NAME: { domain: String, mandatory: true }
|
|
14
|
+
COLOR: { domain: String, mandatory: true }
|
|
15
|
+
constraints:
|
|
16
|
+
pk_parts: { type: :primary_key, attributes: [ 'P#' ] }
|
|
17
|
+
SUPPLIES:
|
|
18
|
+
heading:
|
|
19
|
+
S#: { domain: Integer, mandatory: true }
|
|
20
|
+
P#: { domain: Integer, mandatory: true }
|
|
21
|
+
QTY: { domain: Integer, mandatory: true }
|
|
22
|
+
constraints:
|
|
23
|
+
pk_supplies: { type: :primary_key, attributes: [ 'S#', 'P#' ] }
|
|
24
|
+
---
|
|
25
|
+
physical:
|
|
26
|
+
indexes:
|
|
27
|
+
SUPPLIER_NAMES: { relvar: SUPPLIERS, attributes: [ 'NAME' ] }
|
|
28
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
logical:
|
|
3
|
+
SUPPLIERS:
|
|
4
|
+
heading:
|
|
5
|
+
S#: { domain: Integer, mandatory: true }
|
|
6
|
+
NAME: { domain: String, mandatory: true }
|
|
7
|
+
CITY: { domain: String, mandatory: true }
|
|
8
|
+
constraints:
|
|
9
|
+
pk_suppliers: { type: :primary_key, attributes: [ 'S#' ] }
|
|
10
|
+
PARTS:
|
|
11
|
+
heading:
|
|
12
|
+
P#: { domain: Integer, mandatory: true }
|
|
13
|
+
NAME: { domain: String, mandatory: true }
|
|
14
|
+
COLOR: { domain: String, mandatory: true }
|
|
15
|
+
constraints:
|
|
16
|
+
pk_parts: { type: :primary_key, attributes: [ 'P#' ] }
|
|
17
|
+
---
|
|
18
|
+
physical:
|
|
19
|
+
indexes:
|
|
20
|
+
SUPPLIER_NAMES: { relvar: SUPPLIERS, attributes: [ 'NAME' ] }
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
shared_examples_for("The schema:sql-script command") do
|
|
2
|
+
|
|
3
|
+
let(:invalid){ File.expand_path('../fixtures/invalid.yaml', __FILE__) }
|
|
4
|
+
let(:announced){ File.expand_path('../fixtures/announced.yaml', __FILE__) }
|
|
5
|
+
let(:effective){ File.expand_path('../fixtures/effective.yaml', __FILE__) }
|
|
6
|
+
let(:add_constraint){ File.expand_path('../fixtures/add_constraint.yaml', __FILE__) }
|
|
7
|
+
|
|
8
|
+
it "should return the output buffer with CREATE" do
|
|
9
|
+
dba.output_buffer = StringIO.new
|
|
10
|
+
dba.schema_sql_script(%{create}).should == dba.output_buffer
|
|
11
|
+
s = dba.output_buffer.string
|
|
12
|
+
s.should =~ /CREATE/
|
|
13
|
+
s.should_not =~ /DROP/
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should return the output buffer with DROP" do
|
|
17
|
+
dba.output_buffer = StringIO.new
|
|
18
|
+
dba.schema_sql_script(%{drop}).should == dba.output_buffer
|
|
19
|
+
s = dba.output_buffer.string
|
|
20
|
+
s.should =~ /DROP/
|
|
21
|
+
s.should_not =~ /CREATE/
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should return the output buffer with STAGE (effective vs. announced)" do
|
|
25
|
+
dba.output_buffer = StringIO.new
|
|
26
|
+
dba.schema_sql_script(['stage', effective, announced]).should == dba.output_buffer
|
|
27
|
+
s = dba.output_buffer.string
|
|
28
|
+
s.should =~ /CREATE TABLE .SUPPLIES./
|
|
29
|
+
s.should_not =~ /DROP/
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should return the output buffer with STAGE (announced vs. effective)" do
|
|
33
|
+
dba.output_buffer = StringIO.new
|
|
34
|
+
dba.schema_sql_script(['stage', announced, effective]).should == dba.output_buffer
|
|
35
|
+
s = dba.output_buffer.string
|
|
36
|
+
s.should =~ /DROP TABLE .SUPPLIES./
|
|
37
|
+
s.should_not =~ /CREATE/
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should support adding foreign keys, even if it implies deffered staging" do
|
|
41
|
+
dba.output_buffer = StringIO.new
|
|
42
|
+
s = dba.schema_sql_script(['stage', '--no-check', announced, add_constraint])
|
|
43
|
+
s.should == dba.output_buffer
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should raise an error on invalid schema" do
|
|
47
|
+
s = lambda{ dba.schema_sql_script ['create', invalid ] }
|
|
48
|
+
s.should raise_error(DbAgile::SchemaSemanticsError)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should not raise an error on invalid schema with --no-check" do
|
|
52
|
+
s = lambda{ dba.schema_sql_script ['--no-check', 'create', invalid] }
|
|
53
|
+
s.should_not raise_error(DbAgile::SchemaSemanticsError)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
shared_examples_for("The sql:drop command") do
|
|
2
|
+
|
|
3
|
+
before{
|
|
4
|
+
dba.with_current_connection do |conn|
|
|
5
|
+
conn.transaction do |t|
|
|
6
|
+
t.create_table(:unexisting, {:id => String})
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
}
|
|
10
|
+
after{
|
|
11
|
+
dba.with_current_connection do |conn|
|
|
12
|
+
conn.transaction do |t|
|
|
13
|
+
t.drop_table(:unexisting) if t.has_table?(:unexisting)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
it "should drop the table" do
|
|
19
|
+
dba.sql_drop %{unexisting}
|
|
20
|
+
dba.with_current_connection do |conn|
|
|
21
|
+
conn.has_table?(:unexisting).should be_false
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
DELETE FROM basic_values WHERE id >= 10;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
shared_examples_for("The sql:send command") do
|
|
2
|
+
|
|
3
|
+
it "should print the table on the output buffer" do
|
|
4
|
+
dba.sql_send("SELECT * FROM suppliers")
|
|
5
|
+
dba.output_buffer.string.should =~ /^\+\-/
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "should accept INSERT/DELETE" do
|
|
9
|
+
dba.sql_send("INSERT INTO basic_values (id, name) VALUES (12, 'Hello World')")
|
|
10
|
+
dba.dataset(:basic_values).count.should == 2
|
|
11
|
+
dba.sql_send("DELETE FROM basic_values WHERE id=12")
|
|
12
|
+
dba.dataset(:basic_values).count.should == 1
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "When used with the --file option" do
|
|
16
|
+
|
|
17
|
+
let(:insert){ File.expand_path("../scripts/insert.sql", __FILE__) }
|
|
18
|
+
let(:delete){ File.expand_path("../scripts/delete.sql", __FILE__) }
|
|
19
|
+
|
|
20
|
+
it "should execute the file" do
|
|
21
|
+
dba.sql_send("--file", insert)
|
|
22
|
+
dba.dataset(:basic_values).count.should == 3
|
|
23
|
+
dba.sql_send("-f", delete)
|
|
24
|
+
dba.dataset(:basic_values).count.should == 1
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
shared_examples_for("The sql:show command") do
|
|
2
|
+
|
|
3
|
+
it "should return the output buffer" do
|
|
4
|
+
dba.sql_show(%w{suppliers}).should == dba.output_buffer
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
it "should print the table one the output buffer" do
|
|
8
|
+
dba.sql_show(%w{suppliers})
|
|
9
|
+
dba.output_buffer.string.should =~ /^\+\-/
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should support pretty-printing" do
|
|
13
|
+
dba.sql_show(%w{--pretty suppliers})
|
|
14
|
+
dba.output_buffer.string.should =~ /\.\.\.$/
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
data/test/commands.spec
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
|
2
|
+
dbagile_load_all_subspecs(__FILE__)
|
|
3
|
+
describe "DbAgile::Command::API /" do
|
|
4
|
+
|
|
5
|
+
# The environment to use
|
|
6
|
+
let(:dba){ DbAgile::Command::API.new(DbAgile::Fixtures::environment) }
|
|
7
|
+
|
|
8
|
+
# -- repo
|
|
9
|
+
describe "repo commands /" do
|
|
10
|
+
|
|
11
|
+
# Remove empty repo between all test
|
|
12
|
+
before { dba.repository_path = DbAgile::Fixtures::ensure_empty_repository! }
|
|
13
|
+
after { DbAgile::Fixtures::ensure_empty_repository! }
|
|
14
|
+
|
|
15
|
+
describe "repo:create /" do
|
|
16
|
+
it_should_behave_like "The repo:create command"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end # -- repo
|
|
20
|
+
|
|
21
|
+
# -- db
|
|
22
|
+
describe "db commands (touching) /" do
|
|
23
|
+
|
|
24
|
+
# Remove empty repo between all test
|
|
25
|
+
before { dba.repository_path = DbAgile::Fixtures::ensure_empty_repository! }
|
|
26
|
+
after { DbAgile::Fixtures::ensure_empty_repository! }
|
|
27
|
+
|
|
28
|
+
describe "db:add /" do
|
|
29
|
+
it_should_behave_like "The db:add command"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "db:rm /" do
|
|
33
|
+
it_should_behave_like "The db:rm command"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "db:use /" do
|
|
37
|
+
it_should_behave_like "The db:use command"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end # -- db
|
|
41
|
+
|
|
42
|
+
# -- db
|
|
43
|
+
describe "repository commands (non touching) /" do
|
|
44
|
+
|
|
45
|
+
# Make usage of sqlite for these tests
|
|
46
|
+
before { dba.db_use %{sqlite} }
|
|
47
|
+
|
|
48
|
+
describe "db:list /" do
|
|
49
|
+
it_should_behave_like "The db:list command"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe "db:ping /" do
|
|
53
|
+
it_should_behave_like "The db:ping command"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end # -- db
|
|
57
|
+
|
|
58
|
+
# -- bulk
|
|
59
|
+
describe "bulk commands /" do
|
|
60
|
+
|
|
61
|
+
# Make usage of sqlite for these tests
|
|
62
|
+
before{
|
|
63
|
+
dba.db_use %{sqlite}
|
|
64
|
+
dba.output_buffer = StringIO.new
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describe "bulk:export /" do
|
|
68
|
+
it_should_behave_like "The bulk:export command"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe "bulk:import /" do
|
|
72
|
+
it_should_behave_like "The bulk:import command"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end # -- bulk
|
|
76
|
+
|
|
77
|
+
# -- sql
|
|
78
|
+
describe "sql commands /" do
|
|
79
|
+
|
|
80
|
+
# Make usage of sqlite for these tests
|
|
81
|
+
before{
|
|
82
|
+
dba.db_use %{sqlite}
|
|
83
|
+
dba.output_buffer = StringIO.new
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
describe "sql:send /" do
|
|
87
|
+
it_should_behave_like "The sql:send command"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
describe "sql:show /" do
|
|
91
|
+
it_should_behave_like "The sql:show command"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe "sql:heading /" do
|
|
95
|
+
it_should_behave_like "The sql:heading command"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe "sql:drop /" do
|
|
99
|
+
it_should_behave_like "The sql:drop command"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end # -- sql
|
|
103
|
+
|
|
104
|
+
# -- schema
|
|
105
|
+
describe "schema commands /" do
|
|
106
|
+
|
|
107
|
+
# Make usage of sqlite for these tests
|
|
108
|
+
before{
|
|
109
|
+
dba.db_use %{sqlite}
|
|
110
|
+
dba.output_buffer = StringIO.new
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
describe "schema:dump" do
|
|
114
|
+
it_should_behave_like "The schema:dump command"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe "schema:check" do
|
|
118
|
+
it_should_behave_like "The schema:check command"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
describe "schema:sql-script" do
|
|
122
|
+
it_should_behave_like "The schema:sql-script command"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe "schema:diff" do
|
|
126
|
+
it_should_behave_like "The schema:diff command"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
end # -- schema
|
|
130
|
+
|
|
131
|
+
# -- dba
|
|
132
|
+
describe "main dba command /" do
|
|
133
|
+
|
|
134
|
+
it_should_behave_like "The dba command"
|
|
135
|
+
|
|
136
|
+
end # -- dba
|
|
137
|
+
|
|
138
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
it "should return a Contract::Data::Dataset instance" do
|
|
2
|
+
|
|
3
|
+
subject.dataset(:basic_values).should be_kind_of(DbAgile::Contract::Data::Dataset)
|
|
4
|
+
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
it "should support SQL queries" do
|
|
8
|
+
|
|
9
|
+
subject.dataset("SELECT * FROM basic_values").should be_kind_of(DbAgile::Contract::Data::Dataset)
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should support a projection tuple" do
|
|
14
|
+
|
|
15
|
+
subject.dataset(:basic_values, :id => 1).count.should == 1
|
|
16
|
+
|
|
17
|
+
subject.dataset(:basic_values, :id => 10).count.should == 0
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should support an empty projection tuple" do
|
|
22
|
+
|
|
23
|
+
subject.dataset(:basic_values, {}).count.should == 1
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should support a nil projection tuple" do
|
|
28
|
+
|
|
29
|
+
subject.dataset(:basic_values, nil).count.should == 1
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
it "should return true on non empty result" do
|
|
2
|
+
|
|
3
|
+
subject.exists?(:basic_values, :id => 1).should be_true
|
|
4
|
+
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
it "should return false on empty result" do
|
|
8
|
+
|
|
9
|
+
subject.exists?(:basic_values, :id => 10).should be_false
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
it "should support SQL queries" do
|
|
15
|
+
|
|
16
|
+
subject.exists?("SELECT * FROM basic_values").should be_true
|
|
17
|
+
|
|
18
|
+
subject.exists?("SELECT * FROM basic_values WHERE id=10").should be_false
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should support an empty projection" do
|
|
23
|
+
|
|
24
|
+
subject.exists?(:basic_values, {}).should be_true
|
|
25
|
+
subject.exists?(:empty_table, {}).should be_false
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
it "should support deleting on empty tables" do
|
|
2
|
+
|
|
3
|
+
subject.delete(:empty_table)
|
|
4
|
+
|
|
5
|
+
subject.dataset(:empty_table).count.should == 0
|
|
6
|
+
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should support deleting on non empty tables" do
|
|
10
|
+
|
|
11
|
+
subject.dataset(:non_empty_table).count.should == 2
|
|
12
|
+
|
|
13
|
+
subject.delete(:non_empty_table)
|
|
14
|
+
|
|
15
|
+
subject.dataset(:non_empty_table).count.should == 0
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should allow specifying a projection tuple" do
|
|
20
|
+
|
|
21
|
+
subject.dataset(:non_empty_table).count.should == 2
|
|
22
|
+
|
|
23
|
+
subject.delete(:non_empty_table, :id => 1)
|
|
24
|
+
|
|
25
|
+
subject.dataset(:non_empty_table).to_a.should == [ {:id => 2, :english => "Two"} ]
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
it "should support SELECT queries" do
|
|
2
|
+
|
|
3
|
+
got = subject.direct_sql("SELECT * FROM basic_values")
|
|
4
|
+
|
|
5
|
+
got.should be_kind_of(DbAgile::Contract::Data::Dataset)
|
|
6
|
+
|
|
7
|
+
got.to_a.should == basic_values
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should be smart enough" do
|
|
12
|
+
|
|
13
|
+
subject.direct_sql("SELECT * FROM basic_values").should be_kind_of(DbAgile::Contract::Data::Dataset)
|
|
14
|
+
|
|
15
|
+
subject.direct_sql("select * from basic_values").should be_kind_of(DbAgile::Contract::Data::Dataset)
|
|
16
|
+
|
|
17
|
+
subject.direct_sql(" select * from basic_values where id=1").should be_kind_of(DbAgile::Contract::Data::Dataset)
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
it "should support updating all tuples" do
|
|
2
|
+
|
|
3
|
+
subject.update(:non_empty_table, :english => "None")
|
|
4
|
+
|
|
5
|
+
expected = [{:id => 1, :english => "None"}, {:id => 2, :english => "None"}]
|
|
6
|
+
|
|
7
|
+
subject.dataset(:non_empty_table).to_a.sort{|t1,t2| t1[:id] <=> t2[:id]}.should == expected
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should support updating some tuples only" do
|
|
12
|
+
|
|
13
|
+
subject.update(:non_empty_table, {:english => "None"}, {:id => 1})
|
|
14
|
+
|
|
15
|
+
expected = [{:id => 1, :english => "None"}, {:id => 2, :english => "Two"}]
|
|
16
|
+
|
|
17
|
+
subject.dataset(:non_empty_table).to_a.sort{|t1,t2| t1[:id] <=> t2[:id]}.should == expected
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
shared_examples_for "A Contract::Data::TransactionDriven" do
|
|
2
|
+
|
|
3
|
+
::DbAgile::Contract::Data::TransactionDriven.instance_methods(false).each do |meth|
|
|
4
|
+
it { should respond_to(meth) }
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
after(:each){
|
|
8
|
+
subject.delete(:empty_table)
|
|
9
|
+
}
|
|
10
|
+
after(:each){
|
|
11
|
+
subject.delete(:non_empty_table)
|
|
12
|
+
subject.insert(:non_empty_table, :id => 1, :english => "One")
|
|
13
|
+
subject.insert(:non_empty_table, :id => 2, :english => "Two")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
dbagile_install_examples(__FILE__, self)
|
|
17
|
+
|
|
18
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
shared_examples_for "A robust Contract::Data::TableDriven" do
|
|
2
|
+
|
|
3
|
+
it "should raise a NoSuchTableError on dataset when table does not exists" do
|
|
4
|
+
|
|
5
|
+
lambda { subject.dataset(:unexisting) }.should raise_error(DbAgile::NoSuchTableError)
|
|
6
|
+
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should raise a NoSuchTableError on exists? when table does not exists" do
|
|
10
|
+
|
|
11
|
+
lambda { subject.exists?(:unexisting) }.should raise_error(DbAgile::NoSuchTableError)
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
shared_examples_for "A robust Contract::Data::TransactionDriven" do
|
|
2
|
+
|
|
3
|
+
it "should raise a NoSuchTableError on delete when table does not exists" do
|
|
4
|
+
|
|
5
|
+
lambda { subject.delete(:unexisting) }.should raise_error(DbAgile::NoSuchTableError)
|
|
6
|
+
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should raise a NoSuchTableError on insert when table does not exists" do
|
|
10
|
+
|
|
11
|
+
lambda { subject.insert(:unexisting, :id => 1) }.should raise_error(DbAgile::NoSuchTableError)
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should raise a NoSuchTableError on update when table does not exists" do
|
|
16
|
+
|
|
17
|
+
lambda { subject.update(:unexisting, :id => 1) }.should raise_error(DbAgile::NoSuchTableError)
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
shared_examples_for "A robust Contract::Schema::TableDriven" do
|
|
2
|
+
|
|
3
|
+
it "should raise a NoSuchTableError on column_names when table does not exists" do
|
|
4
|
+
|
|
5
|
+
lambda { subject.column_names(:unexisting) }.should raise_error(DbAgile::NoSuchTableError)
|
|
6
|
+
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should raise a NoSuchTableError on has_column? when table does not exists" do
|
|
10
|
+
|
|
11
|
+
lambda { subject.has_column?(:unexisting, :id) }.should raise_error(DbAgile::NoSuchTableError)
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should raise a NoSuchTableError on heading when table does not exists" do
|
|
16
|
+
|
|
17
|
+
lambda { subject.heading(:unexisting) }.should raise_error(DbAgile::NoSuchTableError)
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|