db_schema 0.3.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +7 -3
- data/db_schema.gemspec +2 -1
- data/lib/db_schema.rb +4 -3
- data/lib/db_schema/normalizer.rb +2 -2
- data/lib/db_schema/reader.rb +8 -350
- data/lib/db_schema/version.rb +1 -1
- metadata +22 -43
- data/lib/db_schema/definitions.rb +0 -10
- data/lib/db_schema/definitions/check_constraint.rb +0 -21
- data/lib/db_schema/definitions/enum.rb +0 -23
- data/lib/db_schema/definitions/extension.rb +0 -12
- data/lib/db_schema/definitions/field.rb +0 -47
- data/lib/db_schema/definitions/field/array.rb +0 -30
- data/lib/db_schema/definitions/field/base.rb +0 -108
- data/lib/db_schema/definitions/field/binary.rb +0 -9
- data/lib/db_schema/definitions/field/bit_string.rb +0 -15
- data/lib/db_schema/definitions/field/boolean.rb +0 -9
- data/lib/db_schema/definitions/field/character.rb +0 -19
- data/lib/db_schema/definitions/field/custom.rb +0 -32
- data/lib/db_schema/definitions/field/datetime.rb +0 -30
- data/lib/db_schema/definitions/field/extensions/chkpass.rb +0 -9
- data/lib/db_schema/definitions/field/extensions/citext.rb +0 -9
- data/lib/db_schema/definitions/field/extensions/cube.rb +0 -9
- data/lib/db_schema/definitions/field/extensions/hstore.rb +0 -9
- data/lib/db_schema/definitions/field/extensions/isn.rb +0 -37
- data/lib/db_schema/definitions/field/extensions/ltree.rb +0 -9
- data/lib/db_schema/definitions/field/extensions/seg.rb +0 -9
- data/lib/db_schema/definitions/field/geometric.rb +0 -33
- data/lib/db_schema/definitions/field/json.rb +0 -13
- data/lib/db_schema/definitions/field/monetary.rb +0 -9
- data/lib/db_schema/definitions/field/network.rb +0 -17
- data/lib/db_schema/definitions/field/numeric.rb +0 -30
- data/lib/db_schema/definitions/field/range.rb +0 -29
- data/lib/db_schema/definitions/field/text_search.rb +0 -13
- data/lib/db_schema/definitions/field/uuid.rb +0 -9
- data/lib/db_schema/definitions/foreign_key.rb +0 -44
- data/lib/db_schema/definitions/index.rb +0 -66
- data/lib/db_schema/definitions/index/column.rb +0 -32
- data/lib/db_schema/definitions/index/expression.rb +0 -19
- data/lib/db_schema/definitions/index/table_field.rb +0 -19
- data/lib/db_schema/definitions/schema.rb +0 -36
- data/lib/db_schema/definitions/table.rb +0 -130
@@ -1,30 +0,0 @@
|
|
1
|
-
module DbSchema
|
2
|
-
module Definitions
|
3
|
-
module Field
|
4
|
-
class Timestamp < Base
|
5
|
-
register :timestamp, :'timestamp without time zone'
|
6
|
-
end
|
7
|
-
|
8
|
-
class Timestamptz < Base
|
9
|
-
register :timestamptz, :'timestamp with time zone'
|
10
|
-
end
|
11
|
-
|
12
|
-
class Date < Base
|
13
|
-
register :date
|
14
|
-
end
|
15
|
-
|
16
|
-
class Time < Base
|
17
|
-
register :time, :'time without time zone'
|
18
|
-
end
|
19
|
-
|
20
|
-
class Timetz < Base
|
21
|
-
register :timetz, :'time with time zone'
|
22
|
-
end
|
23
|
-
|
24
|
-
class Interval < Base
|
25
|
-
register :interval
|
26
|
-
attributes :fields
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module DbSchema
|
2
|
-
module Definitions
|
3
|
-
module Field
|
4
|
-
class EAN13 < Base
|
5
|
-
register :ean13
|
6
|
-
end
|
7
|
-
|
8
|
-
class ISBN13 < Base
|
9
|
-
register :isbn13
|
10
|
-
end
|
11
|
-
|
12
|
-
class ISMN13 < Base
|
13
|
-
register :ismn13
|
14
|
-
end
|
15
|
-
|
16
|
-
class ISSN13 < Base
|
17
|
-
register :issn13
|
18
|
-
end
|
19
|
-
|
20
|
-
class ISBN < Base
|
21
|
-
register :isbn
|
22
|
-
end
|
23
|
-
|
24
|
-
class ISMN < Base
|
25
|
-
register :ismn
|
26
|
-
end
|
27
|
-
|
28
|
-
class ISSN < Base
|
29
|
-
register :issn
|
30
|
-
end
|
31
|
-
|
32
|
-
class UPC < Base
|
33
|
-
register :upc
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module DbSchema
|
2
|
-
module Definitions
|
3
|
-
module Field
|
4
|
-
class Point < Base
|
5
|
-
register :point
|
6
|
-
end
|
7
|
-
|
8
|
-
class Line < Base
|
9
|
-
register :line
|
10
|
-
end
|
11
|
-
|
12
|
-
class Lseg < Base
|
13
|
-
register :lseg
|
14
|
-
end
|
15
|
-
|
16
|
-
class Box < Base
|
17
|
-
register :box
|
18
|
-
end
|
19
|
-
|
20
|
-
class Path < Base
|
21
|
-
register :path
|
22
|
-
end
|
23
|
-
|
24
|
-
class Polygon < Base
|
25
|
-
register :polygon
|
26
|
-
end
|
27
|
-
|
28
|
-
class Circle < Base
|
29
|
-
register :circle
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module DbSchema
|
2
|
-
module Definitions
|
3
|
-
module Field
|
4
|
-
class SmallInt < Base
|
5
|
-
register :smallint
|
6
|
-
end
|
7
|
-
|
8
|
-
class Integer < Base
|
9
|
-
register :integer
|
10
|
-
end
|
11
|
-
|
12
|
-
class BigInt < Base
|
13
|
-
register :bigint
|
14
|
-
end
|
15
|
-
|
16
|
-
class Numeric < Base
|
17
|
-
register :numeric, :decimal
|
18
|
-
attributes :precision, :scale
|
19
|
-
end
|
20
|
-
|
21
|
-
class Real < Base
|
22
|
-
register :real
|
23
|
-
end
|
24
|
-
|
25
|
-
class DoublePrecision < Base
|
26
|
-
register :'double precision', :float
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module DbSchema
|
2
|
-
module Definitions
|
3
|
-
module Field
|
4
|
-
class Int4Range < Base
|
5
|
-
register :int4range
|
6
|
-
end
|
7
|
-
|
8
|
-
class Int8Range < Base
|
9
|
-
register :int8range
|
10
|
-
end
|
11
|
-
|
12
|
-
class NumRange < Base
|
13
|
-
register :numrange
|
14
|
-
end
|
15
|
-
|
16
|
-
class TsRange < Base
|
17
|
-
register :tsrange
|
18
|
-
end
|
19
|
-
|
20
|
-
class TsTzRange < Base
|
21
|
-
register :tstzrange
|
22
|
-
end
|
23
|
-
|
24
|
-
class DateRange < Base
|
25
|
-
register :daterange
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module DbSchema
|
2
|
-
module Definitions
|
3
|
-
class ForeignKey
|
4
|
-
include Dry::Equalizer(:name, :fields, :table, :keys, :on_update, :on_delete, :deferrable?)
|
5
|
-
attr_reader :name, :fields, :table, :keys, :on_update, :on_delete
|
6
|
-
|
7
|
-
def initialize(name:, fields:, table:, keys: [], on_update: :no_action, on_delete: :no_action, deferrable: false)
|
8
|
-
@name = name
|
9
|
-
@fields = fields
|
10
|
-
@table = table
|
11
|
-
@keys = keys
|
12
|
-
@on_update = on_update
|
13
|
-
@on_delete = on_delete
|
14
|
-
@deferrable = deferrable
|
15
|
-
end
|
16
|
-
|
17
|
-
def references_primary_key?
|
18
|
-
keys.empty?
|
19
|
-
end
|
20
|
-
|
21
|
-
def deferrable?
|
22
|
-
@deferrable
|
23
|
-
end
|
24
|
-
|
25
|
-
def options
|
26
|
-
{
|
27
|
-
deferrable: deferrable?,
|
28
|
-
name: name,
|
29
|
-
on_delete: on_delete,
|
30
|
-
on_update: on_update
|
31
|
-
}.tap do |options|
|
32
|
-
options[:key] = keys unless references_primary_key?
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class NullForeignKey < ForeignKey
|
38
|
-
def initialize
|
39
|
-
@fields = []
|
40
|
-
@keys = []
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module DbSchema
|
2
|
-
module Definitions
|
3
|
-
class Index
|
4
|
-
include Dry::Equalizer(:name, :columns, :unique?, :type, :condition)
|
5
|
-
attr_reader :name, :columns, :type, :condition
|
6
|
-
|
7
|
-
def initialize(name:, columns:, unique: false, type: :btree, condition: nil)
|
8
|
-
@name = name.to_sym
|
9
|
-
@columns = columns
|
10
|
-
@unique = unique
|
11
|
-
@type = type
|
12
|
-
@condition = condition
|
13
|
-
end
|
14
|
-
|
15
|
-
def unique?
|
16
|
-
@unique
|
17
|
-
end
|
18
|
-
|
19
|
-
def btree?
|
20
|
-
type == :btree
|
21
|
-
end
|
22
|
-
|
23
|
-
def columns_to_sequel
|
24
|
-
if btree?
|
25
|
-
columns.map(&:ordered_expression)
|
26
|
-
else
|
27
|
-
columns.map(&:to_sequel)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def has_expressions?
|
32
|
-
!condition.nil? || columns.any?(&:expression?)
|
33
|
-
end
|
34
|
-
|
35
|
-
def with_name(new_name)
|
36
|
-
Index.new(
|
37
|
-
name: new_name,
|
38
|
-
columns: columns,
|
39
|
-
unique: unique?,
|
40
|
-
type: type,
|
41
|
-
condition: condition
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
|
-
def with_condition(new_condition)
|
46
|
-
Index.new(
|
47
|
-
name: name,
|
48
|
-
columns: columns,
|
49
|
-
unique: unique?,
|
50
|
-
type: type,
|
51
|
-
condition: new_condition
|
52
|
-
)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class NullIndex < Index
|
57
|
-
def initialize
|
58
|
-
@columns = []
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
require_relative 'index/column'
|
65
|
-
require_relative 'index/table_field'
|
66
|
-
require_relative 'index/expression'
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module DbSchema
|
2
|
-
module Definitions
|
3
|
-
class Index
|
4
|
-
class Column
|
5
|
-
include Dry::Equalizer(:name, :order, :nulls)
|
6
|
-
attr_reader :name, :order, :nulls
|
7
|
-
|
8
|
-
def initialize(name, order: :asc, nulls: order == :asc ? :last : :first)
|
9
|
-
@name = name
|
10
|
-
@order = order
|
11
|
-
@nulls = nulls
|
12
|
-
end
|
13
|
-
|
14
|
-
def asc?
|
15
|
-
@order == :asc
|
16
|
-
end
|
17
|
-
|
18
|
-
def desc?
|
19
|
-
@order == :desc
|
20
|
-
end
|
21
|
-
|
22
|
-
def ordered_expression
|
23
|
-
if asc?
|
24
|
-
Sequel.asc(to_sequel, nulls: nulls)
|
25
|
-
else
|
26
|
-
Sequel.desc(to_sequel, nulls: nulls)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|