dbagile 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (305) hide show
  1. data/LICENCE.textile +12 -0
  2. data/README.textile +89 -0
  3. data/bin/dba +22 -0
  4. data/lib/dbagile/adapter/sequel/class_methods.rb +18 -0
  5. data/lib/dbagile/adapter/sequel/connection.rb +38 -0
  6. data/lib/dbagile/adapter/sequel/data/table_driven.rb +30 -0
  7. data/lib/dbagile/adapter/sequel/data/transaction_driven.rb +43 -0
  8. data/lib/dbagile/adapter/sequel/schema/concrete_script.rb +135 -0
  9. data/lib/dbagile/adapter/sequel/schema/physical_dump.rb +106 -0
  10. data/lib/dbagile/adapter/sequel/schema/schema2sequel_args.rb +71 -0
  11. data/lib/dbagile/adapter/sequel/schema/table_driven.rb +52 -0
  12. data/lib/dbagile/adapter/sequel/schema/transaction_driven.rb +46 -0
  13. data/lib/dbagile/adapter/sequel/sequel_tracer.rb +144 -0
  14. data/lib/dbagile/adapter/sequel.rb +46 -0
  15. data/lib/dbagile/adapter.rb +15 -0
  16. data/lib/dbagile/command/api.rb +49 -0
  17. data/lib/dbagile/command/bulk/commons.rb +130 -0
  18. data/lib/dbagile/command/bulk/export.rb +99 -0
  19. data/lib/dbagile/command/bulk/import.rb +147 -0
  20. data/lib/dbagile/command/bulk.rb +3 -0
  21. data/lib/dbagile/command/class_methods.rb +103 -0
  22. data/lib/dbagile/command/db/add.rb +94 -0
  23. data/lib/dbagile/command/db/list.rb +40 -0
  24. data/lib/dbagile/command/db/ping.rb +49 -0
  25. data/lib/dbagile/command/db/rm.rb +52 -0
  26. data/lib/dbagile/command/db/stage.rb +81 -0
  27. data/lib/dbagile/command/db/use.rb +48 -0
  28. data/lib/dbagile/command/db.rb +6 -0
  29. data/lib/dbagile/command/dba.rb +121 -0
  30. data/lib/dbagile/command/help.rb +50 -0
  31. data/lib/dbagile/command/repo/create.rb +54 -0
  32. data/lib/dbagile/command/repo.rb +1 -0
  33. data/lib/dbagile/command/robust.rb +86 -0
  34. data/lib/dbagile/command/schema/check.rb +59 -0
  35. data/lib/dbagile/command/schema/commons.rb +118 -0
  36. data/lib/dbagile/command/schema/diff.rb +101 -0
  37. data/lib/dbagile/command/schema/dump.rb +48 -0
  38. data/lib/dbagile/command/schema/merge.rb +55 -0
  39. data/lib/dbagile/command/schema/sql_script.rb +124 -0
  40. data/lib/dbagile/command/schema.rb +6 -0
  41. data/lib/dbagile/command/sql/drop.rb +40 -0
  42. data/lib/dbagile/command/sql/heading.rb +34 -0
  43. data/lib/dbagile/command/sql/send.rb +67 -0
  44. data/lib/dbagile/command/sql/show.rb +42 -0
  45. data/lib/dbagile/command/sql.rb +4 -0
  46. data/lib/dbagile/command/web/tools.rb +23 -0
  47. data/lib/dbagile/command/web.rb +1 -0
  48. data/lib/dbagile/command.rb +158 -0
  49. data/lib/dbagile/contract/connection.rb +66 -0
  50. data/lib/dbagile/contract/data/dataset.rb +69 -0
  51. data/lib/dbagile/contract/data/table_driven.rb +49 -0
  52. data/lib/dbagile/contract/data/transaction_driven.rb +74 -0
  53. data/lib/dbagile/contract/data.rb +3 -0
  54. data/lib/dbagile/contract/robust/helpers.rb +19 -0
  55. data/lib/dbagile/contract/robust/optimistic/data/table_driven.rb +31 -0
  56. data/lib/dbagile/contract/robust/optimistic/data/transaction_driven.rb +45 -0
  57. data/lib/dbagile/contract/robust/optimistic/schema/table_driven.rb +53 -0
  58. data/lib/dbagile/contract/robust/optimistic/schema/transaction_driven.rb +45 -0
  59. data/lib/dbagile/contract/robust/optimistic.rb +18 -0
  60. data/lib/dbagile/contract/robust.rb +20 -0
  61. data/lib/dbagile/contract/schema/table_driven.rb +89 -0
  62. data/lib/dbagile/contract/schema/transaction_driven.rb +68 -0
  63. data/lib/dbagile/contract/schema.rb +2 -0
  64. data/lib/dbagile/contract/utils/delegate.rb +17 -0
  65. data/lib/dbagile/contract/utils/full.rb +13 -0
  66. data/lib/dbagile/contract/utils.rb +2 -0
  67. data/lib/dbagile/contract.rb +5 -0
  68. data/lib/dbagile/core/chain.rb +92 -0
  69. data/lib/dbagile/core/connection.rb +51 -0
  70. data/lib/dbagile/core/database.rb +221 -0
  71. data/lib/dbagile/core/io/dsl.rb +95 -0
  72. data/lib/dbagile/core/io/robustness.rb +82 -0
  73. data/lib/dbagile/core/io.rb +2 -0
  74. data/lib/dbagile/core/repository/builder.rb +67 -0
  75. data/lib/dbagile/core/repository/yaml_methods.rb +82 -0
  76. data/lib/dbagile/core/repository.rb +211 -0
  77. data/lib/dbagile/core/schema/builder/coercion.rb +210 -0
  78. data/lib/dbagile/core/schema/builder/concept_factory.rb +61 -0
  79. data/lib/dbagile/core/schema/builder.rb +187 -0
  80. data/lib/dbagile/core/schema/composite.rb +239 -0
  81. data/lib/dbagile/core/schema/computations/filter.rb +40 -0
  82. data/lib/dbagile/core/schema/computations/merge.rb +55 -0
  83. data/lib/dbagile/core/schema/computations/minus.rb +44 -0
  84. data/lib/dbagile/core/schema/computations/split.rb +37 -0
  85. data/lib/dbagile/core/schema/computations.rb +4 -0
  86. data/lib/dbagile/core/schema/database_schema.rb +129 -0
  87. data/lib/dbagile/core/schema/errors.rb +173 -0
  88. data/lib/dbagile/core/schema/logical/attribute.rb +68 -0
  89. data/lib/dbagile/core/schema/logical/constraint/candidate_key.rb +70 -0
  90. data/lib/dbagile/core/schema/logical/constraint/foreign_key.rb +121 -0
  91. data/lib/dbagile/core/schema/logical/constraint.rb +58 -0
  92. data/lib/dbagile/core/schema/logical/constraints.rb +28 -0
  93. data/lib/dbagile/core/schema/logical/heading.rb +47 -0
  94. data/lib/dbagile/core/schema/logical/relvar.rb +81 -0
  95. data/lib/dbagile/core/schema/logical.rb +24 -0
  96. data/lib/dbagile/core/schema/migrate/abstract_script.rb +35 -0
  97. data/lib/dbagile/core/schema/migrate/collapse_table.rb +15 -0
  98. data/lib/dbagile/core/schema/migrate/create_table.rb +15 -0
  99. data/lib/dbagile/core/schema/migrate/drop_table.rb +15 -0
  100. data/lib/dbagile/core/schema/migrate/expand_table.rb +15 -0
  101. data/lib/dbagile/core/schema/migrate/operation.rb +141 -0
  102. data/lib/dbagile/core/schema/migrate/stager.rb +282 -0
  103. data/lib/dbagile/core/schema/migrate.rb +2 -0
  104. data/lib/dbagile/core/schema/part.rb +114 -0
  105. data/lib/dbagile/core/schema/physical/index.rb +64 -0
  106. data/lib/dbagile/core/schema/physical/indexes.rb +12 -0
  107. data/lib/dbagile/core/schema/physical.rb +26 -0
  108. data/lib/dbagile/core/schema/robustness.rb +39 -0
  109. data/lib/dbagile/core/schema/schema_object.rb +94 -0
  110. data/lib/dbagile/core/schema.rb +254 -0
  111. data/lib/dbagile/core/transaction.rb +74 -0
  112. data/lib/dbagile/core.rb +7 -0
  113. data/lib/dbagile/environment/buffering.rb +45 -0
  114. data/lib/dbagile/environment/delegator.rb +59 -0
  115. data/lib/dbagile/environment/interactions.rb +208 -0
  116. data/lib/dbagile/environment/on_error.rb +47 -0
  117. data/lib/dbagile/environment/repository.rb +161 -0
  118. data/lib/dbagile/environment/robustness.rb +7 -0
  119. data/lib/dbagile/environment/testing.rb +23 -0
  120. data/lib/dbagile/environment.rb +122 -0
  121. data/lib/dbagile/errors.rb +30 -0
  122. data/lib/dbagile/io/csv.rb +99 -0
  123. data/lib/dbagile/io/json.rb +41 -0
  124. data/lib/dbagile/io/pretty_table.rb +128 -0
  125. data/lib/dbagile/io/ruby.rb +62 -0
  126. data/lib/dbagile/io/text.rb +18 -0
  127. data/lib/dbagile/io/type_safe.rb +65 -0
  128. data/lib/dbagile/io/xml.rb +35 -0
  129. data/lib/dbagile/io/yaml.rb +30 -0
  130. data/lib/dbagile/io.rb +94 -0
  131. data/lib/dbagile/loader.rb +16 -0
  132. data/lib/dbagile/plugin.rb +29 -0
  133. data/lib/dbagile/restful/client/delete.rb +22 -0
  134. data/lib/dbagile/restful/client/get.rb +24 -0
  135. data/lib/dbagile/restful/client/post.rb +22 -0
  136. data/lib/dbagile/restful/client/utils.rb +16 -0
  137. data/lib/dbagile/restful/client.rb +41 -0
  138. data/lib/dbagile/restful/middleware/delete.rb +22 -0
  139. data/lib/dbagile/restful/middleware/get.rb +27 -0
  140. data/lib/dbagile/restful/middleware/one_database.rb +82 -0
  141. data/lib/dbagile/restful/middleware/post.rb +23 -0
  142. data/lib/dbagile/restful/middleware/utils.rb +65 -0
  143. data/lib/dbagile/restful/middleware.rb +54 -0
  144. data/lib/dbagile/restful/server.rb +65 -0
  145. data/lib/dbagile/restful.rb +9 -0
  146. data/lib/dbagile/robustness/dependencies.rb +36 -0
  147. data/lib/dbagile/robustness/file_system.rb +53 -0
  148. data/lib/dbagile/robustness.rb +14 -0
  149. data/lib/dbagile/tools/file_system.rb +24 -0
  150. data/lib/dbagile/tools/math.rb +11 -0
  151. data/lib/dbagile/tools/ordered_hash.rb +39 -0
  152. data/lib/dbagile/tools/ruby.rb +78 -0
  153. data/lib/dbagile/tools/string.rb +6 -0
  154. data/lib/dbagile/tools/tuple.rb +49 -0
  155. data/lib/dbagile/tools.rb +6 -0
  156. data/lib/dbagile.rb +66 -0
  157. data/test/assumptions/equality.spec +11 -0
  158. data/test/assumptions/fixtures.rb +39 -0
  159. data/test/assumptions/inheritance.spec +17 -0
  160. data/test/assumptions/sequel/autonumber.spec +19 -0
  161. data/test/assumptions/sequel/connect.spec +29 -0
  162. data/test/assumptions/sequel/test.db +0 -0
  163. data/test/assumptions/stdlib/pathname.spec +13 -0
  164. data/test/assumptions/yaml/fixtures.rb +25 -0
  165. data/test/assumptions/yaml/to_yaml.spec +10 -0
  166. data/test/assumptions.spec +2 -0
  167. data/test/commands/bulk/export.spec +100 -0
  168. data/test/commands/bulk/import.spec +49 -0
  169. data/test/commands/db/add.spec +31 -0
  170. data/test/commands/db/list.spec +29 -0
  171. data/test/commands/db/ping.spec +21 -0
  172. data/test/commands/db/rm.spec +18 -0
  173. data/test/commands/db/use.spec +18 -0
  174. data/test/commands/dba.spec +54 -0
  175. data/test/commands/repo/create.spec +30 -0
  176. data/test/commands/schema/check.spec +25 -0
  177. data/test/commands/schema/diff.spec +30 -0
  178. data/test/commands/schema/dump.spec +23 -0
  179. data/test/commands/schema/fixtures/add_constraint.yaml +30 -0
  180. data/test/commands/schema/fixtures/announced.yaml +28 -0
  181. data/test/commands/schema/fixtures/effective.yaml +20 -0
  182. data/test/commands/schema/fixtures/invalid.yaml +6 -0
  183. data/test/commands/schema/sql_script.spec +56 -0
  184. data/test/commands/sql/drop.spec +25 -0
  185. data/test/commands/sql/heading.spec +7 -0
  186. data/test/commands/sql/scripts/delete.sql +1 -0
  187. data/test/commands/sql/scripts/insert.sql +2 -0
  188. data/test/commands/sql/send.spec +29 -0
  189. data/test/commands/sql/show.spec +17 -0
  190. data/test/commands.spec +138 -0
  191. data/test/contract/connection/transaction.ex +11 -0
  192. data/test/contract/connection.spec +9 -0
  193. data/test/contract/data/dataset/columns.ex +5 -0
  194. data/test/contract/data/dataset/count.ex +5 -0
  195. data/test/contract/data/dataset.spec +9 -0
  196. data/test/contract/data/table_driven/dataset.ex +31 -0
  197. data/test/contract/data/table_driven/exists_q.ex +27 -0
  198. data/test/contract/data/table_driven.spec +9 -0
  199. data/test/contract/data/transaction_driven/delete.ex +29 -0
  200. data/test/contract/data/transaction_driven/direct_sql.ex +19 -0
  201. data/test/contract/data/transaction_driven/insert.ex +8 -0
  202. data/test/contract/data/transaction_driven/update.ex +19 -0
  203. data/test/contract/data/transaction_driven.spec +18 -0
  204. data/test/contract/robust/data/table_driven.spec +15 -0
  205. data/test/contract/robust/data/transaction_driven.spec +21 -0
  206. data/test/contract/robust/schema/table_driven.spec +21 -0
  207. data/test/contract/robust/schema/transaction_driven.spec +19 -0
  208. data/test/contract/schema/table_driven/column_names.ex +5 -0
  209. data/test/contract/schema/table_driven/has_column_q.ex +13 -0
  210. data/test/contract/schema/table_driven/has_table_q.ex +11 -0
  211. data/test/contract/schema/table_driven/heading.ex +5 -0
  212. data/test/contract/schema/table_driven.spec +9 -0
  213. data/test/contract/schema/transaction_driven/create_table.ex +10 -0
  214. data/test/contract/schema/transaction_driven/drop_table.ex +10 -0
  215. data/test/contract/schema/transaction_driven.spec +18 -0
  216. data/test/contract.spec +66 -0
  217. data/test/fixtures/basics/data/basic_values.rb +13 -0
  218. data/test/fixtures/basics/data/empty_table.rb +3 -0
  219. data/test/fixtures/basics/data/non_empty_table.rb +4 -0
  220. data/test/fixtures/basics/data/parts.rb +8 -0
  221. data/test/fixtures/basics/data/suppliers.rb +7 -0
  222. data/test/fixtures/basics/data/supplies.rb +14 -0
  223. data/test/fixtures/basics/dbagile.idx +20 -0
  224. data/test/fixtures/basics/fixtures.yaml +28 -0
  225. data/test/fixtures/basics/robust.db +0 -0
  226. data/test/fixtures/basics/suppliers.yaml +30 -0
  227. data/test/fixtures/basics/test.db +0 -0
  228. data/test/fixtures/empty/dbagile.idx +5 -0
  229. data/test/fixtures.rb +152 -0
  230. data/test/restful/delete/no_format.ex +32 -0
  231. data/test/restful/delete.spec +8 -0
  232. data/test/restful/get/csv_format.ex +12 -0
  233. data/test/restful/get/json_format.ex +19 -0
  234. data/test/restful/get/query_string.ex +11 -0
  235. data/test/restful/get/text_format.ex +12 -0
  236. data/test/restful/get/yaml_format.ex +14 -0
  237. data/test/restful/get.spec +5 -0
  238. data/test/restful/post/no_format.ex +22 -0
  239. data/test/restful/post.spec +8 -0
  240. data/test/restful.spec +32 -0
  241. data/test/run_all_suite.rb +51 -0
  242. data/test/spec_helper.rb +26 -0
  243. data/test/support/be_a_valid_json_string.rb +19 -0
  244. data/test/support/be_a_valid_yaml_string.rb +18 -0
  245. data/test/unit/adapter/factor.spec +13 -0
  246. data/test/unit/adapter/sequel/new.spec +19 -0
  247. data/test/unit/command/api.spec +12 -0
  248. data/test/unit/command/command_for.spec +36 -0
  249. data/test/unit/command/command_name_of.spec +21 -0
  250. data/test/unit/command/ruby_method_for.spec +21 -0
  251. data/test/unit/command/sanity.spec +34 -0
  252. data/test/unit/contract/utils/delegate/delegate.spec +23 -0
  253. data/test/unit/core/chain/chain.spec +57 -0
  254. data/test/unit/core/chain/connect.spec +22 -0
  255. data/test/unit/core/chain/delegate_chain.spec +16 -0
  256. data/test/unit/core/chain/initialize.spec +19 -0
  257. data/test/unit/core/chain/plug.spec +31 -0
  258. data/test/unit/core/io/dsl/scope.spec +9 -0
  259. data/test/unit/core/repository/create_bang.spec +31 -0
  260. data/test/unit/core/repository/current.spec +31 -0
  261. data/test/unit/core/repository/database.spec +47 -0
  262. data/test/unit/core/repository/fixtures/corrupted/dbagile.idx +1 -0
  263. data/test/unit/core/repository/fixtures/test_and_prod/dbagile.idx +21 -0
  264. data/test/unit/core/repository/fixtures.rb +25 -0
  265. data/test/unit/core/repository/has_database_q.spec +16 -0
  266. data/test/unit/core/repository/load.spec +51 -0
  267. data/test/unit/core/repository/to_yaml.spec +17 -0
  268. data/test/unit/core/schema/check.spec +32 -0
  269. data/test/unit/core/schema/empty_q.spec +18 -0
  270. data/test/unit/core/schema/filter.spec +42 -0
  271. data/test/unit/core/schema/fixtures/dbagile.yaml +7 -0
  272. data/test/unit/core/schema/fixtures/empty.yaml +11 -0
  273. data/test/unit/core/schema/fixtures/invalid.yaml +54 -0
  274. data/test/unit/core/schema/fixtures/left.yaml +46 -0
  275. data/test/unit/core/schema/fixtures/left_minus_right.yaml +31 -0
  276. data/test/unit/core/schema/fixtures/right.yaml +46 -0
  277. data/test/unit/core/schema/fixtures/right_minus_left.yaml +31 -0
  278. data/test/unit/core/schema/fixtures/suppliers_and_parts.yaml +30 -0
  279. data/test/unit/core/schema/fixtures.rb +32 -0
  280. data/test/unit/core/schema/merge.spec +72 -0
  281. data/test/unit/core/schema/minus.spec +26 -0
  282. data/test/unit/core/schema/sanity.spec +39 -0
  283. data/test/unit/core/schema/split.spec +58 -0
  284. data/test/unit/core/schema/stage_script.spec +26 -0
  285. data/test/unit/core/schema/to_yaml.spec +13 -0
  286. data/test/unit/core/schema/yaml_display.spec +14 -0
  287. data/test/unit/core/schema/yaml_load.spec +20 -0
  288. data/test/unit/core/transaction/transaction.spec +10 -0
  289. data/test/unit/fixtures.rb +67 -0
  290. data/test/unit/io/to_xxx.spec +52 -0
  291. data/test/unit/plugin/options.spec +21 -0
  292. data/test/unit/plugin/tuple_heading.spec +11 -0
  293. data/test/unit/plugin/with_options.spec +12 -0
  294. data/test/unit/tools/ruby/class_unqualified_name.spec +26 -0
  295. data/test/unit/tools/ruby/extract_file_rdoc.spec +10 -0
  296. data/test/unit/tools/ruby/fixtures/rdoc.txt +12 -0
  297. data/test/unit/tools/ruby/fixtures.rb +19 -0
  298. data/test/unit/tools/ruby/optional_args_block_call.spec +35 -0
  299. data/test/unit/tools/ruby/parent_module.spec +21 -0
  300. data/test/unit/tools/ruby/rdoc_file_paragraphs.spec +13 -0
  301. data/test/unit/tools/tuple/tuple_heading.spec +11 -0
  302. data/test/unit/tools/tuple/tuple_key.spec +27 -0
  303. data/test/unit/tools/tuple/tuple_project.spec +23 -0
  304. data/test/unit.spec +3 -0
  305. metadata +422 -0
@@ -0,0 +1,53 @@
1
+ module DbAgile
2
+ module Contract
3
+ module Robust
4
+ class Optimistic
5
+ module Schema
6
+ module TableDriven
7
+
8
+ # @see DbAgile::Contract::Schema::TableDriven#has_column?
9
+ def has_column?(*args, &block)
10
+ delegate.has_column?(*args, &block)
11
+ rescue
12
+ has_table!(args[0])
13
+ raise
14
+ end
15
+
16
+ # @see DbAgile::Contract::Schema::TableDriven#heading
17
+ def heading(*args, &block)
18
+ delegate.heading(*args, &block)
19
+ rescue
20
+ has_table!(args[0])
21
+ raise
22
+ end
23
+
24
+ # @see DbAgile::Contract::Schema::TableDriven#column_names
25
+ def column_names(*args, &block)
26
+ delegate.column_names(*args, &block)
27
+ rescue
28
+ has_table!(args[0])
29
+ raise
30
+ end
31
+
32
+ # @see DbAgile::Contract::Schema::TableDriven#is_key
33
+ def is_key?(*args, &block)
34
+ delegate.is_key?(*args, &block)
35
+ rescue
36
+ has_table!(args[0])
37
+ raise
38
+ end
39
+
40
+ # @see DbAgile::Contract::Schema::TableDriven#keys
41
+ def keys(*args, &block)
42
+ delegate.keys(*args, &block)
43
+ rescue
44
+ has_table!(args[0])
45
+ raise
46
+ end
47
+
48
+ end # module Schema
49
+ end # module Data
50
+ end # class Optimistic
51
+ end # module Robust
52
+ end # module Contract
53
+ end # module DbAgile
@@ -0,0 +1,45 @@
1
+ module DbAgile
2
+ module Contract
3
+ module Robust
4
+ class Optimistic
5
+ module Schema
6
+ module TransactionDriven
7
+
8
+ # @see DbAgile::Contract::Schema::TransactionDriven#create_table
9
+ def create_table(*args, &block)
10
+ delegate.create_table(*args, &block)
11
+ rescue
12
+ not_has_table!(args[1])
13
+ raise
14
+ end
15
+
16
+ # @see DbAgile::Contract::Schema::TransactionDriven#drop_table
17
+ def drop_table(*args, &block)
18
+ delegate.drop_table(*args, &block)
19
+ rescue
20
+ has_table!(args[1])
21
+ raise
22
+ end
23
+
24
+ # @see DbAgile::Contract::Schema::TransactionDriven#add_columns
25
+ def add_columns(*args, &block)
26
+ delegate.add_columns(*args, &block)
27
+ rescue
28
+ has_table!(args[1])
29
+ raise
30
+ end
31
+
32
+ # @see DbAgile::Contract::Schema::TransactionDriven#key!
33
+ def key!(*args, &block)
34
+ delegate.key!(*args, &block)
35
+ rescue
36
+ has_table!(args[1])
37
+ raise
38
+ end
39
+
40
+ end # module TransactionDriven
41
+ end # module Schema
42
+ end # class Optimistic
43
+ end # module Robust
44
+ end # module Contract
45
+ end # module DbAgile
@@ -0,0 +1,18 @@
1
+ require 'dbagile/contract/robust/optimistic/data/table_driven'
2
+ require 'dbagile/contract/robust/optimistic/data/transaction_driven'
3
+ require 'dbagile/contract/robust/optimistic/schema/table_driven'
4
+ require 'dbagile/contract/robust/optimistic/schema/transaction_driven'
5
+ module DbAgile
6
+ module Contract
7
+ module Robust
8
+ class Optimistic
9
+ include DbAgile::Contract::Utils::Delegate
10
+ include DbAgile::Contract::Robust::Helpers
11
+ include DbAgile::Contract::Robust::Optimistic::Data::TableDriven
12
+ include DbAgile::Contract::Robust::Optimistic::Data::TransactionDriven
13
+ include DbAgile::Contract::Robust::Optimistic::Schema::TableDriven
14
+ include DbAgile::Contract::Robust::Optimistic::Schema::TransactionDriven
15
+ end # class Optimistic
16
+ end # module Robust
17
+ end # module Contract
18
+ end # module DbAgile
@@ -0,0 +1,20 @@
1
+ module DbAgile
2
+
3
+ # All errors related to the contract
4
+ class ContractError < DbAgile::Error; end
5
+
6
+ # Raised when a table should not exists but does
7
+ class TableAlreadyExistsError < ContractError; end
8
+
9
+ # Raised when possible when a table does not exists
10
+ class NoSuchTableError < ContractError; end
11
+
12
+ # Raised when a key is violated
13
+ class KeyViolationError < ContractError; end
14
+
15
+ # Internal error used when transaction are aborted
16
+ class AbordTransactionError < ContractError; end
17
+
18
+ end
19
+ require 'dbagile/contract/robust/helpers'
20
+ require 'dbagile/contract/robust/optimistic'
@@ -0,0 +1,89 @@
1
+ module DbAgile
2
+ module Contract
3
+ module Schema
4
+ #
5
+ # Table-driven adapter read-only methods about schemas.
6
+ #
7
+ module TableDriven
8
+
9
+ #
10
+ # Returns true if a given table exists in the database, false otherwise.
11
+ #
12
+ # @param [Symbol] table_name name of a table
13
+ # @return true if the table exists, false otherwise
14
+ #
15
+ def has_table?(table_name)
16
+ Kernel.raise NotImplementedError
17
+ end
18
+
19
+ #
20
+ # Returns true if a column exists, false otherwise.
21
+ #
22
+ # A default implementation is provided that relies on column_names.
23
+ #
24
+ # @param [Symbol] table_name the name of a table
25
+ # @param [Symbol] column_name the name of a column
26
+ # @return true if the column exists on that table, false otherwise
27
+ #
28
+ # @pre [table_name] the table must exist
29
+ #
30
+ def has_column?(table_name, column_name)
31
+ column_names(table_name).include?(column_name)
32
+ end
33
+
34
+ #
35
+ # Returns the heading of a given table.
36
+ #
37
+ # @param [Symbol] table_name the name of a table
38
+ # @return [Hash<Symbol => Class>] table heading
39
+ #
40
+ # @pre [table_name] the table must exist
41
+ #
42
+ def heading(table_name)
43
+ Kernel.raise NotImplementedError
44
+ end
45
+
46
+ #
47
+ # Returns the list of column names for a given table.
48
+ #
49
+ # @param [Symbol] table_name the name of a table
50
+ # @param [Boolean] sort sort column by names?
51
+ # @return [Array<Symbol>] column names
52
+ #
53
+ # @pre [table_name] the table must exist
54
+ #
55
+ def column_names(table_name, sort = false)
56
+ Kernel.raise NotImplementedError
57
+ end
58
+
59
+ #
60
+ # Checks if an array of column names for a key for a given table.
61
+ #
62
+ # @param [Symbol] table_name the name of a table
63
+ # @param [Array<Symbol>] columns column names, in any order
64
+ # @return [Boolean] true if the table contains such a unique key,
65
+ # false otherwise
66
+ #
67
+ # @pre [table_name] the table must exist
68
+ #
69
+ def is_key?(table_name, columns)
70
+ keys(table_name).include?(columns)
71
+ end
72
+
73
+ #
74
+ # Returns available keys for a given table as an array of column
75
+ # names.
76
+ #
77
+ # @param [Symbol] table_name the name of a table
78
+ # @return [Array<Array<Symbol>>] keys of the table
79
+ #
80
+ # @pre [table_name] the table must exist
81
+ #
82
+ def keys(table_name)
83
+ Kernel.raise NotImplementedError
84
+ end
85
+
86
+ end # module TableDriven
87
+ end # module Schema
88
+ end # module Contract
89
+ end # module DbAgile
@@ -0,0 +1,68 @@
1
+ module DbAgile
2
+ module Contract
3
+ module Schema
4
+ module TransactionDriven
5
+
6
+ #
7
+ # Creates a table with some columns.
8
+ #
9
+ # @param [DbAgile::Core::Transaction] transaction the current transaction
10
+ # @param [Symbol] table_name the name of a table
11
+ # @param [Hash] a table heading
12
+ # @return [Hash] the actual table heading that has been created
13
+ #
14
+ # @pre [table_name] the table must not exist
15
+ #
16
+ def create_table(transaction, table_name, columns)
17
+ Kernel.raise NotImplementedError
18
+ end
19
+
20
+ #
21
+ # Drops a table
22
+ #
23
+ # @param [DbAgile::Core::Transaction] transaction the current transaction
24
+ # @param [Symbol] table_name the name of a table
25
+ # @return [Boolean] true to indicate that everything is fine
26
+ #
27
+ # @pre [table_name] the table must not exist
28
+ #
29
+ def drop_table(transaction, table_name)
30
+ Kernel.raise NotImplementedError
31
+ end
32
+
33
+ #
34
+ # Adds some columns to a table
35
+ #
36
+ # @param [DbAgile::Core::Transaction] transaction the current transaction
37
+ # @param [Symbol] table_name the name of a table
38
+ # @param [Hash] columns column definitions
39
+ # @return [Boolean] true to indicate that everything is fine
40
+ #
41
+ # @pre [table_name] the table must not exist
42
+ # @pre [columns] the table may not contain any of the columns
43
+ # @post the table has gained the additional columns
44
+ #
45
+ def add_columns(transaction, table_name, columns)
46
+ Kernel.raise NotImplementedError
47
+ end
48
+
49
+ #
50
+ # Make columns be a candidate key for the table.
51
+ #
52
+ # @param [DbAgile::Core::Transaction] transaction the current transaction
53
+ # @param [Symbol] table_name the name of a table
54
+ # @param [Array<Symbol>] columns column names
55
+ # @return [Boolean] true to indicate that everything is fine
56
+ #
57
+ # @pre [table_name] the table must not exist
58
+ # @pre [columns] the table must have all columns
59
+ # @post the table has gained the candidate key
60
+ #
61
+ def key!(transaction, table_name, columns)
62
+ Kernel.raise NotImplementedError
63
+ end
64
+
65
+ end # module TransactionDriven
66
+ end # module Schema
67
+ end # module Contract
68
+ end # module DbAgile
@@ -0,0 +1,2 @@
1
+ require 'dbagile/contract/schema/table_driven'
2
+ require 'dbagile/contract/schema/transaction_driven'
@@ -0,0 +1,17 @@
1
+ module DbAgile
2
+ module Contract
3
+ module Utils
4
+ module Delegate
5
+
6
+ DbAgile::Contract::Utils::Full.instance_methods(true).each do |meth|
7
+ module_eval <<-EOF
8
+ def #{meth}(*args, &block)
9
+ delegate.#{meth}(*args, &block)
10
+ end
11
+ EOF
12
+ end
13
+
14
+ end # module Delegate
15
+ end # module Utils
16
+ end # module Contract
17
+ end # module DbAgile
@@ -0,0 +1,13 @@
1
+ module DbAgile
2
+ module Contract
3
+ module Utils
4
+ module Full
5
+ include DbAgile::Contract::Connection
6
+ include DbAgile::Contract::Data::TableDriven
7
+ include DbAgile::Contract::Data::TransactionDriven
8
+ include DbAgile::Contract::Schema::TableDriven
9
+ include DbAgile::Contract::Schema::TransactionDriven
10
+ end # module Full
11
+ end # module Utils
12
+ end # module Contract
13
+ end # module DbAgile
@@ -0,0 +1,2 @@
1
+ require 'dbagile/contract/utils/full'
2
+ require 'dbagile/contract/utils/delegate'
@@ -0,0 +1,5 @@
1
+ require 'dbagile/contract/connection'
2
+ require 'dbagile/contract/data'
3
+ require 'dbagile/contract/schema'
4
+ require 'dbagile/contract/utils'
5
+ require 'dbagile/contract/robust'
@@ -0,0 +1,92 @@
1
+ require 'delegate'
2
+ require 'enumerator'
3
+ module DbAgile
4
+ module Core
5
+ class Chain
6
+
7
+ # A participant in the chain
8
+ module Participant
9
+ def __getobj__() @__delegate__ end
10
+ alias :delegate :__getobj__
11
+ end
12
+
13
+ # Returns the delegator chain
14
+ attr_reader :delegate_chain
15
+
16
+ # Creates a chain instance. Shortcut for Chain.new(*args)
17
+ def self.[](*args)
18
+ Chain.new(*args)
19
+ end
20
+
21
+ # Creates an empty chain
22
+ def initialize(*chain)
23
+ @delegate_chain = []
24
+ plug(*chain) unless chain.empty?
25
+ __install_chain__
26
+ end
27
+
28
+ # Handles the magic of delegation through \_\_getobj\_\_.
29
+ def method_missing(m, *args, &block)
30
+ target = self.__getobj__
31
+ unless target.respond_to?(m)
32
+ super
33
+ end
34
+ target.__send__(m, *args, &block)
35
+ end
36
+
37
+ # Builds some participants
38
+ def __build_participants__(args)
39
+ delegates = []
40
+ until args.empty?
41
+ case arg = args.shift
42
+ when Class
43
+ mod_args = []
44
+ until args.empty? or args[0].kind_of?(Module)
45
+ mod_args << args.shift
46
+ end
47
+ delegates << arg.new(*mod_args)
48
+ else
49
+ delegates << arg
50
+ end
51
+ end
52
+ delegates
53
+ end
54
+
55
+ # Installs the chain
56
+ def __install_chain__
57
+ delegate_chain.each_cons(2) do |part, its_del|
58
+ part.extend(Participant)
59
+ part.instance_eval{ @__delegate__ = its_del }
60
+ end
61
+ end
62
+
63
+ # Returns the delegation object
64
+ def __getobj__
65
+ delegate_chain.first
66
+ end
67
+
68
+ # Plugs some chain participants
69
+ def plug(*args)
70
+ @delegate_chain = __build_participants__(args) + delegate_chain
71
+ __install_chain__
72
+ self
73
+ end
74
+
75
+ # Returns a connected version of self.
76
+ def connect(last)
77
+ chain = delegate_chain + [ last ]
78
+ Chain.new(*chain)
79
+ end
80
+
81
+ # Inspects this chain
82
+ def inspect
83
+ debug = delegate_chain.collect{|c|
84
+ c.kind_of?(Chain) ? c.inspect : c.class.name
85
+ }.join(', ')
86
+ "[#{debug}]"
87
+ end
88
+
89
+ protected :__getobj__
90
+ end # class Chain
91
+ end # module Core
92
+ end # module DbAgile
@@ -0,0 +1,51 @@
1
+ module DbAgile
2
+ module Core
3
+ class Connection
4
+
5
+ attr_reader :chain
6
+
7
+ # About creation ###############################################################
8
+
9
+ # Creates a database instance with an underlying adapter
10
+ def initialize(chain)
11
+ @chain = chain
12
+ end
13
+
14
+ # About delegate chains ########################################################
15
+
16
+ # Hot plug
17
+ def plug(*args)
18
+ @chain.plug(*args)
19
+ end
20
+
21
+ # Delegated to the chain
22
+ def inspect
23
+ @chain.inspect
24
+ end
25
+
26
+ ### DELEGATE PATTERN ON CONNECTION ################################################
27
+
28
+ # Automatically install methods of the Connection and *::TableDriven contracts
29
+ [ DbAgile::Contract::Connection,
30
+ DbAgile::Contract::Data::TableDriven,
31
+ DbAgile::Contract::Schema::TableDriven ].each do |mod|
32
+
33
+ mod.instance_methods(false).each do |method|
34
+ self.module_eval <<-EOF
35
+ def #{method}(*args, &block)
36
+ @chain.#{method}(*args, &block)
37
+ end
38
+ EOF
39
+ end
40
+
41
+ end
42
+
43
+ # Executes the block inside a transaction.
44
+ def transaction(&block)
45
+ raise ArgumentError, "Missing transaction block" unless block
46
+ Transaction.new(self).execute(&block)
47
+ end
48
+
49
+ end # class Connection
50
+ end # module Core
51
+ end # module DbAgile