db_schema 0.3.1 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +7 -3
  3. data/db_schema.gemspec +2 -1
  4. data/lib/db_schema.rb +4 -3
  5. data/lib/db_schema/normalizer.rb +2 -2
  6. data/lib/db_schema/reader.rb +8 -350
  7. data/lib/db_schema/version.rb +1 -1
  8. metadata +22 -43
  9. data/lib/db_schema/definitions.rb +0 -10
  10. data/lib/db_schema/definitions/check_constraint.rb +0 -21
  11. data/lib/db_schema/definitions/enum.rb +0 -23
  12. data/lib/db_schema/definitions/extension.rb +0 -12
  13. data/lib/db_schema/definitions/field.rb +0 -47
  14. data/lib/db_schema/definitions/field/array.rb +0 -30
  15. data/lib/db_schema/definitions/field/base.rb +0 -108
  16. data/lib/db_schema/definitions/field/binary.rb +0 -9
  17. data/lib/db_schema/definitions/field/bit_string.rb +0 -15
  18. data/lib/db_schema/definitions/field/boolean.rb +0 -9
  19. data/lib/db_schema/definitions/field/character.rb +0 -19
  20. data/lib/db_schema/definitions/field/custom.rb +0 -32
  21. data/lib/db_schema/definitions/field/datetime.rb +0 -30
  22. data/lib/db_schema/definitions/field/extensions/chkpass.rb +0 -9
  23. data/lib/db_schema/definitions/field/extensions/citext.rb +0 -9
  24. data/lib/db_schema/definitions/field/extensions/cube.rb +0 -9
  25. data/lib/db_schema/definitions/field/extensions/hstore.rb +0 -9
  26. data/lib/db_schema/definitions/field/extensions/isn.rb +0 -37
  27. data/lib/db_schema/definitions/field/extensions/ltree.rb +0 -9
  28. data/lib/db_schema/definitions/field/extensions/seg.rb +0 -9
  29. data/lib/db_schema/definitions/field/geometric.rb +0 -33
  30. data/lib/db_schema/definitions/field/json.rb +0 -13
  31. data/lib/db_schema/definitions/field/monetary.rb +0 -9
  32. data/lib/db_schema/definitions/field/network.rb +0 -17
  33. data/lib/db_schema/definitions/field/numeric.rb +0 -30
  34. data/lib/db_schema/definitions/field/range.rb +0 -29
  35. data/lib/db_schema/definitions/field/text_search.rb +0 -13
  36. data/lib/db_schema/definitions/field/uuid.rb +0 -9
  37. data/lib/db_schema/definitions/foreign_key.rb +0 -44
  38. data/lib/db_schema/definitions/index.rb +0 -66
  39. data/lib/db_schema/definitions/index/column.rb +0 -32
  40. data/lib/db_schema/definitions/index/expression.rb +0 -19
  41. data/lib/db_schema/definitions/index/table_field.rb +0 -19
  42. data/lib/db_schema/definitions/schema.rb +0 -36
  43. data/lib/db_schema/definitions/table.rb +0 -130
@@ -1,3 +1,3 @@
1
1
  module DbSchema
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vsevolod Romashov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-25 00:00:00.000000000 Z
11
+ date: 2018-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: db_schema-definitions
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -151,19 +165,19 @@ dependencies:
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
- name: pg
168
+ name: db_schema-reader-postgres
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
- - - ">="
171
+ - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: '0'
173
+ version: 0.1.1
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
- - - ">="
178
+ - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '0'
180
+ version: 0.1.1
167
181
  description: A database schema management tool that reads a "single-source-of-truth"
168
182
  schema definition from a ruby file and auto-migrates the database to conform to
169
183
  it.
@@ -188,41 +202,6 @@ files:
188
202
  - lib/db_schema/awesome_print.rb
189
203
  - lib/db_schema/changes.rb
190
204
  - lib/db_schema/configuration.rb
191
- - lib/db_schema/definitions.rb
192
- - lib/db_schema/definitions/check_constraint.rb
193
- - lib/db_schema/definitions/enum.rb
194
- - lib/db_schema/definitions/extension.rb
195
- - lib/db_schema/definitions/field.rb
196
- - lib/db_schema/definitions/field/array.rb
197
- - lib/db_schema/definitions/field/base.rb
198
- - lib/db_schema/definitions/field/binary.rb
199
- - lib/db_schema/definitions/field/bit_string.rb
200
- - lib/db_schema/definitions/field/boolean.rb
201
- - lib/db_schema/definitions/field/character.rb
202
- - lib/db_schema/definitions/field/custom.rb
203
- - lib/db_schema/definitions/field/datetime.rb
204
- - lib/db_schema/definitions/field/extensions/chkpass.rb
205
- - lib/db_schema/definitions/field/extensions/citext.rb
206
- - lib/db_schema/definitions/field/extensions/cube.rb
207
- - lib/db_schema/definitions/field/extensions/hstore.rb
208
- - lib/db_schema/definitions/field/extensions/isn.rb
209
- - lib/db_schema/definitions/field/extensions/ltree.rb
210
- - lib/db_schema/definitions/field/extensions/seg.rb
211
- - lib/db_schema/definitions/field/geometric.rb
212
- - lib/db_schema/definitions/field/json.rb
213
- - lib/db_schema/definitions/field/monetary.rb
214
- - lib/db_schema/definitions/field/network.rb
215
- - lib/db_schema/definitions/field/numeric.rb
216
- - lib/db_schema/definitions/field/range.rb
217
- - lib/db_schema/definitions/field/text_search.rb
218
- - lib/db_schema/definitions/field/uuid.rb
219
- - lib/db_schema/definitions/foreign_key.rb
220
- - lib/db_schema/definitions/index.rb
221
- - lib/db_schema/definitions/index/column.rb
222
- - lib/db_schema/definitions/index/expression.rb
223
- - lib/db_schema/definitions/index/table_field.rb
224
- - lib/db_schema/definitions/schema.rb
225
- - lib/db_schema/definitions/table.rb
226
205
  - lib/db_schema/dsl.rb
227
206
  - lib/db_schema/dsl/migration.rb
228
207
  - lib/db_schema/migration.rb
@@ -254,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
233
  version: '0'
255
234
  requirements: []
256
235
  rubyforge_project:
257
- rubygems_version: 2.6.13
236
+ rubygems_version: 2.7.6
258
237
  signing_key:
259
238
  specification_version: 4
260
239
  summary: Declarative database schema definition.
@@ -1,10 +0,0 @@
1
- require 'dry/equalizer'
2
-
3
- require_relative 'definitions/schema'
4
- require_relative 'definitions/table'
5
- require_relative 'definitions/field'
6
- require_relative 'definitions/index'
7
- require_relative 'definitions/foreign_key'
8
- require_relative 'definitions/check_constraint'
9
- require_relative 'definitions/enum'
10
- require_relative 'definitions/extension'
@@ -1,21 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- class CheckConstraint
4
- include Dry::Equalizer(:name, :condition)
5
- attr_reader :name, :condition
6
-
7
- def initialize(name:, condition:)
8
- @name = name.to_sym
9
- @condition = condition
10
- end
11
-
12
- def with_condition(new_condition)
13
- CheckConstraint.new(name: name, condition: new_condition)
14
- end
15
- end
16
-
17
- class NullCheckConstraint < CheckConstraint
18
- def initialize; end
19
- end
20
- end
21
- end
@@ -1,23 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- class Enum
4
- include Dry::Equalizer(:name, :values)
5
- attr_reader :name, :values
6
-
7
- def initialize(name, values)
8
- @name = name
9
- @values = values
10
- end
11
-
12
- def with_name(new_name)
13
- Enum.new(new_name, values)
14
- end
15
- end
16
-
17
- class NullEnum < Enum
18
- def initialize
19
- @values = []
20
- end
21
- end
22
- end
23
- end
@@ -1,12 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- class Extension
4
- include Dry::Equalizer(:name)
5
- attr_reader :name
6
-
7
- def initialize(name)
8
- @name = name
9
- end
10
- end
11
- end
12
- end
@@ -1,47 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- module Field
4
- class << self
5
- def build(name, type, **options)
6
- type_class_for(type).new(name, **options)
7
- end
8
-
9
- def type_class_for(type)
10
- registry.fetch(type) do |type|
11
- Custom.class_for(type)
12
- end
13
- end
14
-
15
- def registry
16
- @registry ||= {}
17
- end
18
- end
19
- end
20
- end
21
- end
22
-
23
- require_relative 'field/base'
24
- require_relative 'field/numeric'
25
- require_relative 'field/monetary'
26
- require_relative 'field/character'
27
- require_relative 'field/binary'
28
- require_relative 'field/datetime'
29
- require_relative 'field/boolean'
30
- require_relative 'field/geometric'
31
- require_relative 'field/network'
32
- require_relative 'field/bit_string'
33
- require_relative 'field/text_search'
34
- require_relative 'field/uuid'
35
- require_relative 'field/json'
36
- require_relative 'field/array'
37
- require_relative 'field/range'
38
-
39
- require_relative 'field/extensions/chkpass'
40
- require_relative 'field/extensions/citext'
41
- require_relative 'field/extensions/cube'
42
- require_relative 'field/extensions/hstore'
43
- require_relative 'field/extensions/isn'
44
- require_relative 'field/extensions/ltree'
45
- require_relative 'field/extensions/seg'
46
-
47
- require_relative 'field/custom'
@@ -1,30 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- module Field
4
- class Array < Base
5
- register :array
6
-
7
- def initialize(name, **options)
8
- type_class = Field.type_class_for(options[:element_type])
9
- super(name, **options.merge(element_type: type_class))
10
- end
11
-
12
- def attributes
13
- super.merge(element_type: element_type.type)
14
- end
15
-
16
- def array?
17
- true
18
- end
19
-
20
- def element_type
21
- @attributes[:element_type]
22
- end
23
-
24
- def custom_element_type?
25
- element_type.superclass == Custom
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,108 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- module Field
4
- class Base
5
- include Dry::Equalizer(:name, :type, :primary_key?, :options)
6
- attr_reader :name, :default
7
-
8
- def initialize(name, primary_key: false, null: true, default: nil, **attributes)
9
- @name = name
10
- @primary_key = primary_key
11
- @null = null
12
- @default = default
13
- @attributes = attributes
14
- end
15
-
16
- def primary_key?
17
- @primary_key
18
- end
19
-
20
- def null?
21
- !primary_key? && @null
22
- end
23
-
24
- def default_is_expression?
25
- default.is_a?(Symbol)
26
- end
27
-
28
- def array?
29
- false
30
- end
31
-
32
- def custom?
33
- false
34
- end
35
-
36
- def options
37
- attributes.tap do |options|
38
- options[:null] = false unless null?
39
- options[:default] = default unless default.nil?
40
- end
41
- end
42
-
43
- def attributes
44
- self.class.valid_attributes.reduce({}) do |hash, attr_name|
45
- if attr_value = @attributes[attr_name]
46
- hash.merge(attr_name => attr_value)
47
- elsif default_value = self.class.default_attribute_values[attr_name]
48
- hash.merge(attr_name => default_value)
49
- else
50
- hash
51
- end
52
- end
53
- end
54
-
55
- def type
56
- self.class.type
57
- end
58
-
59
- def with_type(new_type)
60
- Field.build(name, new_type, **options, primary_key: primary_key?)
61
- end
62
-
63
- def with_attribute(attr_name, attr_value)
64
- Field.build(name, type, **options, primary_key: primary_key?, attr_name => attr_value)
65
- end
66
-
67
- def with_default(new_default)
68
- Field.build(name, type, **options, primary_key: primary_key?, default: new_default)
69
- end
70
-
71
- class << self
72
- def register(*types)
73
- types.each do |type|
74
- Field.registry[type] = self
75
- end
76
- end
77
-
78
- def attributes(*attr_names, **attributes_with_defaults)
79
- valid_attributes.push(*attr_names)
80
-
81
- attributes_with_defaults.each do |attr_name, default_value|
82
- valid_attributes.push(attr_name)
83
- default_attribute_values[attr_name] = default_value
84
- end
85
- end
86
-
87
- def valid_attributes
88
- @valid_attributes ||= []
89
- end
90
-
91
- def default_attribute_values
92
- @default_attribute_values ||= {}
93
- end
94
-
95
- def type
96
- Field.registry.key(self)
97
- end
98
- end
99
- end
100
- end
101
-
102
- class NullField < Field::Base
103
- def initialize
104
- super(nil)
105
- end
106
- end
107
- end
108
- end
@@ -1,9 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- module Field
4
- class Bytea < Base
5
- register :bytea
6
- end
7
- end
8
- end
9
- end
@@ -1,15 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- module Field
4
- class Bit < Base
5
- register :bit
6
- attributes length: 1
7
- end
8
-
9
- class Varbit < Base
10
- register :varbit, :'bit varying'
11
- attributes :length
12
- end
13
- end
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- module Field
4
- class Boolean < Base
5
- register :boolean
6
- end
7
- end
8
- end
9
- end
@@ -1,19 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- module Field
4
- class Char < Base
5
- register :char, :character
6
- attributes length: 1
7
- end
8
-
9
- class Varchar < Base
10
- register :varchar, :'character varying'
11
- attributes :length
12
- end
13
-
14
- class Text < Base
15
- register :text
16
- end
17
- end
18
- end
19
- end
@@ -1,32 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- module Field
4
- class Custom < Base
5
- class << self
6
- def class_for(type_name)
7
- raise ArgumentError if type_name.nil?
8
-
9
- custom_types[type_name] ||= Class.new(self) do
10
- define_method :type do
11
- type_name
12
- end
13
-
14
- define_singleton_method :type do
15
- type_name
16
- end
17
-
18
- define_method :custom? do
19
- true
20
- end
21
- end
22
- end
23
-
24
- private
25
- def custom_types
26
- @custom_types ||= {}
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end