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,19 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- class Index
4
- class Expression < Column
5
- def expression?
6
- true
7
- end
8
-
9
- def index_name_segment
10
- name.scan(/\b[A-Za-z0-9_]+\b/).join('_')
11
- end
12
-
13
- def to_sequel
14
- Sequel.lit("(#{name})")
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- class Index
4
- class TableField < Column
5
- def expression?
6
- false
7
- end
8
-
9
- def index_name_segment
10
- name
11
- end
12
-
13
- def to_sequel
14
- name
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,36 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- class Schema
4
- include Dry::Equalizer(:tables, :enums, :extensions)
5
- attr_reader :tables, :enums, :extensions
6
- attr_writer :tables
7
-
8
- def initialize(tables: [], enums: [], extensions: [])
9
- @tables = tables
10
- @enums = enums
11
- @extensions = extensions
12
- end
13
-
14
- def table(table_name)
15
- tables.find { |table| table.name == table_name } || NullTable.new
16
- end
17
- alias_method :[], :table
18
-
19
- def has_table?(table_name)
20
- !table(table_name).is_a?(NullTable)
21
- end
22
-
23
- def enum(enum_name)
24
- enums.find { |enum| enum.name == enum_name } || NullEnum.new
25
- end
26
-
27
- def has_enum?(enum_name)
28
- !enum(enum_name).is_a?(NullEnum)
29
- end
30
-
31
- def has_extension?(extension_name)
32
- extensions.any? { |extension| extension.name == extension_name }
33
- end
34
- end
35
- end
36
- end
@@ -1,130 +0,0 @@
1
- module DbSchema
2
- module Definitions
3
- class Table
4
- include Dry::Equalizer(:name, :fields, :indexes, :checks, :foreign_keys)
5
- attr_reader :name, :fields, :indexes, :checks, :foreign_keys
6
-
7
- def initialize(name, fields: [], indexes: [], checks: [], foreign_keys: [])
8
- @name = name.to_sym
9
- @fields = fields
10
- @indexes = indexes
11
- @checks = checks
12
- @foreign_keys = foreign_keys
13
- end
14
-
15
- def has_expressions?
16
- fields.any?(&:default_is_expression?) ||
17
- indexes.any?(&:has_expressions?) ||
18
- checks.any?
19
- end
20
-
21
- def field(field_name)
22
- fields.find { |field| field.name == field_name } || NullField.new
23
- end
24
- alias_method :[], :field
25
-
26
- def has_field?(field_name)
27
- !field(field_name).is_a?(NullField)
28
- end
29
-
30
- def index(index_name)
31
- indexes.find { |index| index.name == index_name } || NullIndex.new
32
- end
33
-
34
- def has_index?(index_name)
35
- !index(index_name).is_a?(NullIndex)
36
- end
37
-
38
- def has_index_on?(*field_names)
39
- indexes.any? do |index|
40
- index.columns.none?(&:expression?) && index.columns.map(&:name) == field_names
41
- end
42
- end
43
-
44
- def has_unique_index_on?(*field_names)
45
- indexes.any? do |index|
46
- index.unique? && index.columns.none?(&:expression?) && index.columns.map(&:name) == field_names
47
- end
48
- end
49
-
50
- def check(check_name)
51
- checks.find { |check| check.name == check_name } || NullCheckConstraint.new
52
- end
53
-
54
- def has_check?(check_name)
55
- !check(check_name).is_a?(NullCheckConstraint)
56
- end
57
-
58
- def foreign_key(fkey_name)
59
- foreign_keys.find { |fkey| fkey.name == fkey_name } || NullForeignKey.new
60
- end
61
-
62
- def has_foreign_key?(fkey_name)
63
- !foreign_key(fkey_name).is_a?(NullForeignKey)
64
- end
65
-
66
- def has_foreign_key_to?(other_table_name)
67
- foreign_keys.any? { |fkey| fkey.table == other_table_name }
68
- end
69
-
70
- def with_name(new_name)
71
- Table.new(
72
- new_name,
73
- fields: fields,
74
- indexes: indexes,
75
- checks: checks,
76
- foreign_keys: foreign_keys
77
- )
78
- end
79
-
80
- def with_fields(new_fields)
81
- Table.new(
82
- name,
83
- fields: new_fields,
84
- indexes: indexes,
85
- checks: checks,
86
- foreign_keys: foreign_keys
87
- )
88
- end
89
-
90
- def with_indexes(new_indexes)
91
- Table.new(
92
- name,
93
- fields: fields,
94
- indexes: new_indexes,
95
- checks: checks,
96
- foreign_keys: foreign_keys
97
- )
98
- end
99
-
100
- def with_checks(new_checks)
101
- Table.new(
102
- name,
103
- fields: fields,
104
- indexes: indexes,
105
- checks: new_checks,
106
- foreign_keys: foreign_keys
107
- )
108
- end
109
-
110
- def with_foreign_keys(new_foreign_keys)
111
- Table.new(
112
- name,
113
- fields: fields,
114
- indexes: indexes,
115
- checks: checks,
116
- foreign_keys: new_foreign_keys
117
- )
118
- end
119
- end
120
-
121
- class NullTable < Table
122
- def initialize
123
- @fields = []
124
- @indexes = []
125
- @checks = []
126
- @foreign_keys = []
127
- end
128
- end
129
- end
130
- end