skyward-orm 0.3.0 → 0.4.0

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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +200 -31
  3. data/lib/skyward/orm/adapters/postgresql.rb +140 -38
  4. data/lib/skyward/orm/adapters/sqlite/constraints.rb +18 -0
  5. data/lib/skyward/orm/adapters/sqlite.rb +130 -21
  6. data/lib/skyward/orm/adapters.rb +12 -2
  7. data/lib/skyward/orm/catalog/column.rb +2 -1
  8. data/lib/skyward/orm/cli/boot_file.rb +2 -2
  9. data/lib/skyward/orm/cli/migrate.rb +1 -1
  10. data/lib/skyward/orm/cli/migration.rb +1 -1
  11. data/lib/skyward/orm/cli/scaffold/source.rb +304 -0
  12. data/lib/skyward/orm/cli/scaffold.rb +70 -0
  13. data/lib/skyward/orm/cli/status.rb +5 -3
  14. data/lib/skyward/orm/commands.rb +12 -0
  15. data/lib/skyward/orm/connection/instrumented.rb +69 -0
  16. data/lib/skyward/orm/connection/session.rb +74 -5
  17. data/lib/skyward/orm/{connection/database → database}/schema_check.rb +20 -8
  18. data/lib/skyward/orm/{connection/database.rb → database.rb} +15 -15
  19. data/lib/skyward/orm/execution.rb +9 -0
  20. data/lib/skyward/orm/migrations/alter_table.rb +6 -2
  21. data/lib/skyward/orm/migrations/definitions.rb +7 -4
  22. data/lib/skyward/orm/migrations/diff.rb +154 -30
  23. data/lib/skyward/orm/migrations/rename_constraint.rb +8 -0
  24. data/lib/skyward/orm/migrations/runner.rb +13 -3
  25. data/lib/skyward/orm/migrations/script.rb +60 -20
  26. data/lib/skyward/orm/migrations/status.rb +32 -3
  27. data/lib/skyward/orm/migrations/summary.rb +3 -6
  28. data/lib/skyward/orm/migrations/versions.rb +1 -1
  29. data/lib/skyward/orm/migrations.rb +1 -1
  30. data/lib/skyward/orm/projection.rb +23 -4
  31. data/lib/skyward/orm/queries/clauses.rb +117 -32
  32. data/lib/skyward/orm/record.rb +23 -1
  33. data/lib/skyward/orm/{placeholders.rb → statements/placeholders.rb} +1 -1
  34. data/lib/skyward/orm/statements.rb +171 -30
  35. data/lib/skyward/orm/tables/column.rb +2 -1
  36. data/lib/skyward/orm/tables/column_types.rb +62 -15
  37. data/lib/skyward/orm/tables/declarations.rb +38 -10
  38. data/lib/skyward/orm/{members.rb → tables/members.rb} +1 -1
  39. data/lib/skyward/orm/tables/sources.rb +63 -0
  40. data/lib/skyward/orm/tables/validation.rb +12 -3
  41. data/lib/skyward/orm/tables/values.rb +115 -5
  42. data/lib/skyward/orm/tables.rb +2 -1
  43. data/lib/skyward/orm/transactional.rb +2 -2
  44. data/lib/skyward/orm/version.rb +1 -1
  45. data/lib/skyward/orm.rb +44 -10
  46. data/sig/generated/skyward/orm/adapters/postgresql.rbs +53 -14
  47. data/sig/generated/skyward/orm/adapters/sqlite/constraints.rbs +6 -0
  48. data/sig/generated/skyward/orm/adapters/sqlite.rbs +67 -7
  49. data/sig/generated/skyward/orm/adapters.rbs +3 -0
  50. data/sig/generated/skyward/orm/catalog/column.rbs +6 -4
  51. data/sig/generated/skyward/orm/cli/boot_file.rbs +4 -4
  52. data/sig/generated/skyward/orm/cli/migrate.rbs +2 -2
  53. data/sig/generated/skyward/orm/cli/migration.rbs +2 -2
  54. data/sig/generated/skyward/orm/cli/scaffold/source.rbs +147 -0
  55. data/sig/generated/skyward/orm/cli/scaffold.rbs +28 -0
  56. data/sig/generated/skyward/orm/cli/status.rbs +2 -2
  57. data/sig/generated/skyward/orm/connection/instrumented.rbs +45 -0
  58. data/sig/generated/skyward/orm/connection/session.rbs +40 -6
  59. data/sig/generated/skyward/orm/{connection/database → database}/schema_check.rbs +11 -4
  60. data/sig/generated/skyward/orm/{connection/database.rbs → database.rbs} +4 -5
  61. data/sig/generated/skyward/orm/execution.rbs +18 -0
  62. data/sig/generated/skyward/orm/migrations/alter_table.rbs +11 -5
  63. data/sig/generated/skyward/orm/migrations/definitions.rbs +2 -2
  64. data/sig/generated/skyward/orm/migrations/diff.rbs +77 -11
  65. data/sig/generated/skyward/orm/migrations/rename_constraint.rbs +16 -0
  66. data/sig/generated/skyward/orm/migrations/runner.rbs +5 -0
  67. data/sig/generated/skyward/orm/migrations/script.rbs +32 -8
  68. data/sig/generated/skyward/orm/migrations/status.rbs +15 -2
  69. data/sig/generated/skyward/orm/migrations/summary.rbs +0 -1
  70. data/sig/generated/skyward/orm/migrations/versions.rbs +2 -2
  71. data/sig/generated/skyward/orm/migrations.rbs +1 -1
  72. data/sig/generated/skyward/orm/projection.rbs +10 -2
  73. data/sig/generated/skyward/orm/queries/clauses.rbs +60 -24
  74. data/sig/generated/skyward/orm/record.rbs +8 -0
  75. data/sig/generated/skyward/orm/{placeholders.rbs → statements/placeholders.rbs} +2 -2
  76. data/sig/generated/skyward/orm/statements.rbs +83 -5
  77. data/sig/generated/skyward/orm/tables/column.rbs +6 -4
  78. data/sig/generated/skyward/orm/tables/column_types.rbs +18 -4
  79. data/sig/generated/skyward/orm/tables/declarations.rbs +15 -1
  80. data/sig/generated/skyward/orm/{members.rbs → tables/members.rbs} +2 -2
  81. data/sig/generated/skyward/orm/tables/sources.rbs +32 -0
  82. data/sig/generated/skyward/orm/tables/values.rbs +41 -1
  83. data/sig/generated/skyward/orm/tables.rbs +3 -1
  84. data/sig/generated/skyward/orm.rbs +6 -6
  85. data/sig/manual/pg.rbs +12 -0
  86. data/sig/manual/skyward/orm/cli/scaffold/source.rbs +3 -0
  87. data/sig/manual/skyward/orm/cli/scaffold.rbs +3 -0
  88. data/sig/manual/skyward/orm/database/schema_check.rbs +3 -0
  89. data/sig/manual/skyward/orm/statements/placeholders.rbs +3 -0
  90. data/sig/manual/skyward/orm/tables/members.rbs +3 -0
  91. data/sig/manual/skyward/orm/tables/sources.rbs +3 -0
  92. data/sig/manual/skyward/orm.rbs +32 -5
  93. metadata +43 -14
  94. data/sig/manual/skyward/orm/connection/database/schema_check.rbs +0 -3
  95. data/sig/manual/skyward/orm/members.rbs +0 -3
  96. data/sig/manual/skyward/orm/placeholders.rbs +0 -3
@@ -0,0 +1,147 @@
1
+ # Generated from lib/skyward/orm/cli/scaffold/source.rb with RBS::Inline
2
+
3
+ # A table class's file, written from its table as the catalog reads it. Each
4
+ # type, default and constraint is one the class's migration would write the
5
+ # same, so `skyward migration` changes only what a comment says it will.
6
+ module Skyward::ORM::CLI::Scaffold::Source
7
+ # Only a trailing s is dropped: ies becomes y, sses becomes ss, and ss stays.
8
+ SINGULAR: Regexp
9
+
10
+ SINGULARS: Hash[String, String]
11
+
12
+ QUOTED: Regexp
13
+
14
+ LITERAL: Regexp
15
+
16
+ ISO_DATE: Regexp
17
+
18
+ # A Time as SQLite's adapter decodes it, to the microsecond. PostgreSQL reads
19
+ # a default back with a cast, so no Time is written back the same there.
20
+ ISO_TIME: Regexp
21
+
22
+ BOOLS: Hash[String, bool]
23
+
24
+ ENUM: Skyward::ORM::Tables::Column
25
+
26
+ PARENTHESIZED: Regexp
27
+
28
+ CHECK: Regexp
29
+
30
+ # What's left of a check that lists a column's values once its strings,
31
+ # casts and punctuation are gone. SQLite keeps `priority IN ('low', 'high')`,
32
+ # and PostgreSQL rewrites it as `priority = ANY (ARRAY['low'::text, 'high'::text])`.
33
+ CAST: Regexp
34
+
35
+ PUNCTUATION: Regexp
36
+
37
+ LISTS: Array[String]
38
+
39
+ # A btree index on columns alone, as PostgreSQL writes one back, or as it was written on SQLite.
40
+ PLAIN_INDEX: Regexp
41
+
42
+ # The columns a foreign key names after the table it references, if it names any.
43
+ REFERENCED: Regexp
44
+
45
+ DROPPED: String
46
+
47
+ REWRITTEN: String
48
+
49
+ # @rbs (Skyward::ORM::Catalog::Table table, Array[Skyward::ORM::Catalog::Table] tables,
50
+ # Skyward::ORM::_Adapter adapter, Array[singleton(Skyward::ORM::Record)] classes) -> String
51
+ def text: (Skyward::ORM::Catalog::Table table, Array[Skyward::ORM::Catalog::Table] tables, Skyward::ORM::_Adapter adapter, Array[singleton(Skyward::ORM::Record)] classes) -> String
52
+
53
+ # @rbs table: Symbol
54
+ # @rbs return: String
55
+ def class_name: (Symbol table) -> String
56
+
57
+ # @rbs table: Skyward::ORM::Catalog::Table?
58
+ # @rbs return: Array[Symbol]
59
+ def primary_key: (Skyward::ORM::Catalog::Table? table) -> Array[Symbol]
60
+
61
+ private
62
+
63
+ # Each line below `table`, in the README's order, with what the class can't
64
+ # declare first, as a comment.
65
+ # @rbs (Skyward::ORM::Catalog::Table table, Array[Skyward::ORM::Catalog::Table] tables,
66
+ # Skyward::ORM::_Adapter adapter, Array[singleton(Skyward::ORM::Record)] classes,
67
+ # Array[Skyward::ORM::Catalog::Constraint] checks, Hash[Symbol, Skyward::ORM::Tables::column_type?] types)
68
+ # -> Array[String]
69
+ def declarations: (Skyward::ORM::Catalog::Table table, Array[Skyward::ORM::Catalog::Table] tables, Skyward::ORM::_Adapter adapter, Array[singleton(Skyward::ORM::Record)] classes, Array[Skyward::ORM::Catalog::Constraint] checks, Hash[Symbol, Skyward::ORM::Tables::column_type?] types) -> Array[String]
70
+
71
+ # @rbs columns: Array[Skyward::ORM::Catalog::Column]
72
+ # @rbs unions: Hash[Symbol, [Skyward::ORM::Catalog::Constraint, Array[Symbol]]]
73
+ # @rbs types: Hash[Symbol, Skyward::ORM::Tables::column_type?]
74
+ # @rbs return: Array[String]
75
+ def readers: (Array[Skyward::ORM::Catalog::Column] columns, Hash[Symbol, [ Skyward::ORM::Catalog::Constraint, Array[Symbol] ]] unions, Hash[Symbol, Skyward::ORM::Tables::column_type?] types) -> Array[String]
76
+
77
+ # A text column whose check lists only strings is a symbol union, and its
78
+ # type makes that check.
79
+ # @rbs (Skyward::ORM::Catalog::Column column, Array[Skyward::ORM::Catalog::Constraint] checks,
80
+ # Skyward::ORM::_Adapter adapter) -> [Skyward::ORM::Catalog::Constraint, Array[Symbol]]?
81
+ def union: (Skyward::ORM::Catalog::Column column, Array[Skyward::ORM::Catalog::Constraint] checks, Skyward::ORM::_Adapter adapter) -> [ Skyward::ORM::Catalog::Constraint, Array[Symbol] ]?
82
+
83
+ # A literal the column's type reads is that value, if it's written back the
84
+ # same. Anything else is SQL, without the parentheses SQLite's adapter puts
85
+ # back, since its default_expression adds them again. The bool says whether
86
+ # it's written back the same. SQLite keeps a literal as it was written, even
87
+ # in parentheses, so one no value writes back the same, such as 1.50, is the
88
+ # value it reads as, which a migration rewrites it as once, or nil when it
89
+ # reads as none.
90
+ # @rbs (Skyward::ORM::Catalog::Column column, Skyward::ORM::Tables::column_type? type,
91
+ # Skyward::ORM::_Adapter adapter) -> [Skyward::ORM::Catalog::Column, String?, bool]?
92
+ def default: (Skyward::ORM::Catalog::Column column, Skyward::ORM::Tables::column_type? type, Skyward::ORM::_Adapter adapter) -> [ Skyward::ORM::Catalog::Column, String?, bool ]?
93
+
94
+ # @rbs sql: String
95
+ # @rbs type: Skyward::ORM::Tables::column_type?
96
+ # @rbs return: Array[untyped]
97
+ def values: (String sql, Skyward::ORM::Tables::column_type? type) -> Array[untyped]
98
+
99
+ # @rbs string: String?
100
+ # @rbs return: Date?
101
+ def date: (String? string) -> Date?
102
+
103
+ # @rbs string: String?
104
+ # @rbs return: Time?
105
+ def time: (String? string) -> Time?
106
+
107
+ # @rbs value: untyped
108
+ # @rbs return: String
109
+ def ruby: (untyped value) -> String
110
+
111
+ # A foreign key a class declares is on one column, and refers to the
112
+ # primary key of the table it references.
113
+ # @rbs constraint: Skyward::ORM::Catalog::Constraint
114
+ # @rbs tables: Array[Skyward::ORM::Catalog::Table]
115
+ # @rbs return: bool
116
+ def reference?: (Skyward::ORM::Catalog::Constraint constraint, Array[Skyward::ORM::Catalog::Table] tables) -> bool
117
+
118
+ # @rbs table: Symbol
119
+ # @rbs constraint: Skyward::ORM::Catalog::Constraint
120
+ # @rbs classes: Array[singleton(Skyward::ORM::Record)]
121
+ # @rbs return: Array[String]
122
+ def reference: (Symbol table, Skyward::ORM::Catalog::Constraint constraint, Array[singleton(Skyward::ORM::Record)] classes) -> Array[String]
123
+
124
+ # @rbs index: Skyward::ORM::Catalog::Index
125
+ # @rbs return: bool
126
+ def plain?: (Skyward::ORM::Catalog::Index index) -> bool
127
+
128
+ # @rbs check: Skyward::ORM::Catalog::Constraint
129
+ # @rbs return: String
130
+ def rule: (Skyward::ORM::Catalog::Constraint check) -> String
131
+
132
+ # @rbs declaration: String
133
+ # @rbs key: Skyward::ORM::Catalog::Constraint | Skyward::ORM::Catalog::Index
134
+ # @rbs return: String
135
+ def columns: (String declaration, Skyward::ORM::Catalog::Constraint | Skyward::ORM::Catalog::Index key) -> String
136
+
137
+ # Every line of the text is commented, since a definition or name the
138
+ # database keeps can hold a newline.
139
+ # @rbs text: String
140
+ # @rbs prefix: String
141
+ # @rbs return: String
142
+ def comment: (String text, ?String prefix) -> String
143
+
144
+ # @rbs undeclarable: Skyward::ORM::Catalog::Column | Skyward::ORM::Catalog::Constraint | Skyward::ORM::Catalog::Index
145
+ # @rbs return: String
146
+ def definition: (Skyward::ORM::Catalog::Column | Skyward::ORM::Catalog::Constraint | Skyward::ORM::Catalog::Index undeclarable) -> String
147
+ end
@@ -0,0 +1,28 @@
1
+ # Generated from lib/skyward/orm/cli/scaffold.rb with RBS::Inline
2
+
3
+ module Skyward::ORM::CLI::Scaffold
4
+ USAGE: String
5
+
6
+ # A row compiles @name for each column, and has these methods of its own.
7
+ COLUMN: Regexp
8
+
9
+ TAKEN: Array[Symbol]
10
+
11
+ # @rbs (Array[String] args, directory: String, out: _Writer, kernel: singleton(Kernel),
12
+ # session: Skyward::ORM::Connection::Session, discover: ^() -> Array[singleton(Skyward::ORM::Record)],
13
+ # generate: ^() -> String?) -> void
14
+ def run: (Array[String] args, directory: String, out: _Writer, kernel: singleton(Kernel), session: Skyward::ORM::Connection::Session, discover: ^() -> Array[singleton(Skyward::ORM::Record)], generate: ^() -> String?) -> void
15
+
16
+ private
17
+
18
+ # @rbs name: String
19
+ # @rbs tables: Array[Skyward::ORM::Catalog::Table]
20
+ # @rbs classes: Array[singleton(Skyward::ORM::Record)]
21
+ # @rbs return: Skyward::ORM::Catalog::Table | String
22
+ def find: (String name, Array[Skyward::ORM::Catalog::Table] tables, Array[singleton(Skyward::ORM::Record)] classes) -> (Skyward::ORM::Catalog::Table | String)
23
+
24
+ # @rbs table: Skyward::ORM::Catalog::Table
25
+ # @rbs classes: Array[singleton(Skyward::ORM::Record)]
26
+ # @rbs return: String?
27
+ def refusal: (Skyward::ORM::Catalog::Table table, Array[singleton(Skyward::ORM::Record)] classes) -> String?
28
+ end
@@ -11,7 +11,7 @@ module Skyward::ORM::CLI::Status
11
11
 
12
12
  private
13
13
 
14
- # @rbs (Skyward::ORM::Connection::Database database, directory: String, out: _Writer, kernel: singleton(Kernel),
14
+ # @rbs (Skyward::ORM::Database database, directory: String, out: _Writer, kernel: singleton(Kernel),
15
15
  # discover: ^() -> Array[singleton(Skyward::ORM::Record)]) -> void
16
- def report: (Skyward::ORM::Connection::Database database, directory: String, out: _Writer, kernel: singleton(Kernel), discover: ^() -> Array[singleton(Skyward::ORM::Record)]) -> void
16
+ def report: (Skyward::ORM::Database database, directory: String, out: _Writer, kernel: singleton(Kernel), discover: ^() -> Array[singleton(Skyward::ORM::Record)]) -> void
17
17
  end
@@ -0,0 +1,45 @@
1
+ # Generated from lib/skyward/orm/connection/instrumented.rb with RBS::Inline
2
+
3
+ class Skyward::ORM::Connection::Instrumented
4
+ ONCE: String
5
+
6
+ @connection: Skyward::ORM::_Connection
7
+
8
+ @instrument: Skyward::ORM::_Instrument
9
+
10
+ @adapter: Symbol
11
+
12
+ @clock_ms: ^() -> Float
13
+
14
+ # @rbs (Skyward::ORM::_Connection connection, Skyward::ORM::_Instrument instrument, Symbol adapter,
15
+ # clock_ms: ^() -> Float) -> void
16
+ def initialize: (Skyward::ORM::_Connection connection, Skyward::ORM::_Instrument instrument, Symbol adapter, clock_ms: ^() -> Float) -> void
17
+
18
+ # @rbs sql: String
19
+ # @rbs binds: Array[untyped]
20
+ # @rbs return: Array[Array[untyped]]
21
+ def execute: (String sql, ?Array[untyped] binds) -> Array[Array[untyped]]
22
+
23
+ # @rbs sql: String
24
+ # @rbs *binds: untyped
25
+ # @rbs return: Array[Array[untyped]]
26
+ def execute2: (String sql, *untyped binds) -> Array[Array[untyped]]
27
+
28
+ # @rbs sql: String
29
+ # @rbs return: void
30
+ def execute_batch: (String sql) -> void
31
+
32
+ # @rbs return: Integer
33
+ def changes: () -> Integer
34
+
35
+ # @rbs return: bool
36
+ def transaction_active?: () -> bool
37
+
38
+ # @rbs return: void
39
+ def close: () -> void
40
+
41
+ private
42
+
43
+ # @rbs [T] (String sql, Array[untyped] binds) { () -> T } -> T
44
+ def instrumented: [T] (String sql, Array[untyped] binds) { () -> T } -> T
45
+ end
@@ -1,19 +1,39 @@
1
1
  # Generated from lib/skyward/orm/connection/session.rb with RBS::Inline
2
2
 
3
3
  class Skyward::ORM::Connection::Session
4
- @database: Skyward::ORM::Connection::Database?
4
+ @database: Skyward::ORM::Database?
5
5
 
6
6
  @check: bool
7
7
 
8
+ @current: Symbol
9
+
10
+ @holding: Symbol
11
+
8
12
  # @rbs return: void
9
13
  def initialize: () -> void
10
14
 
11
- # @rbs database: Skyward::ORM::Connection::Database
12
- # @rbs return: Skyward::ORM::Connection::Database
13
- def connect: (Skyward::ORM::Connection::Database database) -> Skyward::ORM::Connection::Database
15
+ # @rbs database: Skyward::ORM::Database
16
+ # @rbs return: Skyward::ORM::Database
17
+ def connect: (Skyward::ORM::Database database) -> Skyward::ORM::Database
18
+
19
+ # @rbs return: Skyward::ORM::Database
20
+ def database: () -> Skyward::ORM::Database
21
+
22
+ # Fiber storage is copied into the fibers and threads a fiber starts, so
23
+ # those it starts in the block inherit the switch.
24
+ # @rbs [T] (Skyward::ORM::Database database) { () -> T } -> T
25
+ def using: [T] (Skyward::ORM::Database database) { () -> T } -> T
26
+
27
+ # A transaction on the current database, for a test, and on each database
28
+ # its fiber switches to, until #release rolls them all back. The holding is
29
+ # kept before the database holds, so #release finds one that took a
30
+ # connection and then raised.
31
+ # @rbs return: void
32
+ def hold: () -> void
14
33
 
15
- # @rbs return: Skyward::ORM::Connection::Database
16
- def database: () -> Skyward::ORM::Connection::Database
34
+ # Nothing is held when #hold raised before it could find a database.
35
+ # @rbs return: void
36
+ def release: () -> void
17
37
 
18
38
  # @rbs return: bool
19
39
  def check?: () -> bool
@@ -22,4 +42,18 @@ class Skyward::ORM::Connection::Session
22
42
  # fixes a schema that doesn't match, and its boot.rb connects with the default.
23
43
  # @rbs [T] () { () -> T } -> T
24
44
  def without_check: [T] () { () -> T } -> T
45
+
46
+ private
47
+
48
+ # Only the fiber that holds: the holding is fiber-local rather than in fiber
49
+ # storage, so a fiber or thread it starts doesn't inherit it, since nothing
50
+ # would release what one held.
51
+ # @rbs database: Skyward::ORM::Database
52
+ # @rbs return: void
53
+ def hold_also: (Skyward::ORM::Database database) -> void
54
+
55
+ # Each database is released even when one before it raises.
56
+ # @rbs databases: Array[Skyward::ORM::Database]
57
+ # @rbs return: void
58
+ def release_each: (Array[Skyward::ORM::Database] databases) -> void
25
59
  end
@@ -1,6 +1,6 @@
1
- # Generated from lib/skyward/orm/connection/database/schema_check.rb with RBS::Inline
1
+ # Generated from lib/skyward/orm/database/schema_check.rb with RBS::Inline
2
2
 
3
- module Skyward::ORM::Connection::Database::SchemaCheck
3
+ module Skyward::ORM::Database::SchemaCheck
4
4
  type problem = [ String, String, String ]
5
5
 
6
6
  MIGRATE: String
@@ -13,9 +13,16 @@ module Skyward::ORM::Connection::Database::SchemaCheck
13
13
 
14
14
  private
15
15
 
16
+ # A missing column is suggested only one the class doesn't declare, since
17
+ # one added with no migration yet would otherwise be pointed at another.
16
18
  # @rbs (singleton(Skyward::ORM::Record) klass, Skyward::ORM::Catalog::Table table,
17
- # Skyward::ORM::Tables::Column column, Skyward::ORM::_Adapter adapter) -> Array[problem]
18
- def column_problems: (singleton(Skyward::ORM::Record) klass, Skyward::ORM::Catalog::Table table, Skyward::ORM::Tables::Column column, Skyward::ORM::_Adapter adapter) -> Array[problem]
19
+ # Skyward::ORM::Tables::Column column, Array[Symbol] undeclared, Skyward::ORM::_Adapter adapter) -> Array[problem]
20
+ def column_problems: (singleton(Skyward::ORM::Record) klass, Skyward::ORM::Catalog::Table table, Skyward::ORM::Tables::Column column, Array[Symbol] undeclared, Skyward::ORM::_Adapter adapter) -> Array[problem]
21
+
22
+ # @rbs name: Symbol
23
+ # @rbs names: Array[Symbol]
24
+ # @rbs return: String
25
+ def suggest: (Symbol name, Array[Symbol] names) -> String
19
26
 
20
27
  # @rbs stored: String
21
28
  # @rbs declared: String
@@ -1,6 +1,6 @@
1
- # Generated from lib/skyward/orm/connection/database.rb with RBS::Inline
1
+ # Generated from lib/skyward/orm/database.rb with RBS::Inline
2
2
 
3
- class Skyward::ORM::Connection::Database
3
+ class Skyward::ORM::Database
4
4
  class Held < Data
5
5
  attr_reader connection(): Skyward::ORM::_Connection
6
6
 
@@ -207,10 +207,9 @@ class Skyward::ORM::Connection::Database
207
207
  def build: (singleton(Skyward::ORM::Record) table, Class row, Array[Symbol] expressed) -> ^(Array[untyped]) -> untyped
208
208
 
209
209
  # @rbs row: Class
210
- # @rbs members: Array[Symbol]
211
- # @rbs types: Array[Skyward::ORM::Tables::column_type]
210
+ # @rbs columns: Array[Skyward::ORM::Tables::Column]
212
211
  # @rbs return: ^(Array[untyped]) -> untyped
213
- def compile: (Class row, Array[Symbol] members, Array[Skyward::ORM::Tables::column_type] types) -> ^(Array[untyped]) -> untyped
212
+ def compile: (Class row, Array[Skyward::ORM::Tables::Column] columns) -> ^(Array[untyped]) -> untyped
214
213
 
215
214
  # Raw SQL returns rows, with no room for a violation, so one raises.
216
215
  # @rbs sql: String
@@ -0,0 +1,18 @@
1
+ # Generated from lib/skyward/orm/execution.rb with RBS::Inline
2
+
3
+ module Skyward::ORM
4
+ class Execution < Data
5
+ attr_reader sql(): String
6
+
7
+ attr_reader binds(): Array[untyped]
8
+
9
+ attr_reader adapter(): Symbol
10
+
11
+ def self.new: (String sql, Array[untyped] binds, Symbol adapter) -> instance
12
+ | (sql: String, binds: Array[untyped], adapter: Symbol) -> instance
13
+
14
+ def self.members: () -> [ :sql, :binds, :adapter ]
15
+
16
+ def members: () -> [ :sql, :binds, :adapter ]
17
+ end
18
+ end
@@ -2,7 +2,9 @@
2
2
 
3
3
  module Skyward::ORM::Migrations
4
4
  # A table that differs from its class: the class's columns, the table as the
5
- # database has it, and each difference, in the order the migration makes them.
5
+ # database has it, each difference, in the order the migration makes them,
6
+ # and the indexes and constraints the table keeps because the class can't
7
+ # declare them.
6
8
  class AlterTable < Data
7
9
  attr_reader klass(): singleton(Skyward::ORM::Record)
8
10
 
@@ -12,11 +14,15 @@ module Skyward::ORM::Migrations
12
14
 
13
15
  attr_reader edits(): Array[edit]
14
16
 
15
- def self.new: (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns, Skyward::ORM::Catalog::Table table, Array[edit] edits) -> instance
16
- | (klass: singleton(Skyward::ORM::Record), columns: Array[Skyward::ORM::Tables::Column], table: Skyward::ORM::Catalog::Table, edits: Array[edit]) -> instance
17
+ attr_reader kept_indexes(): Array[Skyward::ORM::Catalog::Index]
17
18
 
18
- def self.members: () -> [ :klass, :columns, :table, :edits ]
19
+ attr_reader kept_constraints(): Array[Skyward::ORM::Catalog::Constraint]
19
20
 
20
- def members: () -> [ :klass, :columns, :table, :edits ]
21
+ def self.new: (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns, Skyward::ORM::Catalog::Table table, Array[edit] edits, Array[Skyward::ORM::Catalog::Index] kept_indexes, Array[Skyward::ORM::Catalog::Constraint] kept_constraints) -> instance
22
+ | (klass: singleton(Skyward::ORM::Record), columns: Array[Skyward::ORM::Tables::Column], table: Skyward::ORM::Catalog::Table, edits: Array[edit], kept_indexes: Array[Skyward::ORM::Catalog::Index], kept_constraints: Array[Skyward::ORM::Catalog::Constraint]) -> instance
23
+
24
+ def self.members: () -> [ :klass, :columns, :table, :edits, :kept_indexes, :kept_constraints ]
25
+
26
+ def members: () -> [ :klass, :columns, :table, :edits, :kept_indexes, :kept_constraints ]
21
27
  end
22
28
  end
@@ -22,10 +22,10 @@ module Skyward::ORM::Migrations::Definitions
22
22
 
23
23
  # The SQL that follows the column's DEFAULT, or nil when it has none.
24
24
  # @rbs klass: singleton(Skyward::ORM::Record)
25
- # @rbs column: Symbol
25
+ # @rbs column: Skyward::ORM::Tables::Column
26
26
  # @rbs adapter: Skyward::ORM::_Adapter
27
27
  # @rbs return: String?
28
- def default: (singleton(Skyward::ORM::Record) klass, Symbol column, Skyward::ORM::_Adapter adapter) -> String?
28
+ def default: (singleton(Skyward::ORM::Record) klass, Skyward::ORM::Tables::Column column, Skyward::ORM::_Adapter adapter) -> String?
29
29
 
30
30
  # The constraint as a column's own, in a column's definition.
31
31
  # @rbs constraint: Skyward::ORM::Catalog::Constraint
@@ -5,6 +5,26 @@ module Skyward::ORM::Migrations::Diff
5
5
 
6
6
  NULL: String
7
7
 
8
+ RENAMABLE: Array[Skyward::ORM::Catalog::constraint_kind]
9
+
10
+ # A name as SQLite or PostgreSQL writes it, quoted or not.
11
+ NAME: Regexp
12
+
13
+ # A name with its schema, if it has one.
14
+ QUALIFIED: Regexp
15
+
16
+ # An index a class can declare: on columns alone, by PostgreSQL's btree,
17
+ # with no WHERE or INCLUDE, and not unique, since a class makes that only as
18
+ # a unique constraint.
19
+ PLAIN_INDEX: Regexp
20
+
21
+ # The columns a foreign key names after its table, if it names any.
22
+ REFERENCED: Regexp
23
+
24
+ QUOTED: Regexp
25
+
26
+ BY_VALUE: Array[Skyward::ORM::Tables::column_type]
27
+
8
28
  # New tables come first, each after the tables it references, so a changed
9
29
  # table can reference a new table too. A table with no class is left alone:
10
30
  # a class that isn't loaded looks the same.
@@ -13,6 +33,16 @@ module Skyward::ORM::Migrations::Diff
13
33
  # ^(Symbol table, Symbol from, Symbol to) -> bool rename) -> Array[Skyward::ORM::Migrations::change]
14
34
  def changes: (Array[singleton(Skyward::ORM::Record)] classes, Skyward::ORM::Tables::ColumnTypes column_types, Array[Skyward::ORM::Catalog::Table] tables, Skyward::ORM::_Adapter adapter, ^(Symbol table, Symbol from, Symbol to) -> bool rename) -> Array[Skyward::ORM::Migrations::change]
15
35
 
36
+ # The indexes and constraints the table has that the class can't declare,
37
+ # which the diff neither drops nor adds. PostgreSQL puts a check on every
38
+ # column it mentions, so one the class declares is matched by its name first.
39
+ # @rbs klass: singleton(Skyward::ORM::Record)
40
+ # @rbs columns: Array[Skyward::ORM::Tables::Column]
41
+ # @rbs table: Skyward::ORM::Catalog::Table
42
+ # @rbs tables: Array[Skyward::ORM::Catalog::Table]
43
+ # @rbs return: [Array[Skyward::ORM::Catalog::Index], Array[Skyward::ORM::Catalog::Constraint]]
44
+ def kept: (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns, Skyward::ORM::Catalog::Table table, Array[Skyward::ORM::Catalog::Table] tables) -> [ Array[Skyward::ORM::Catalog::Index], Array[Skyward::ORM::Catalog::Constraint] ]
45
+
16
46
  private
17
47
 
18
48
  # @rbs classes: Array[singleton(Skyward::ORM::Record)]
@@ -22,9 +52,9 @@ module Skyward::ORM::Migrations::Diff
22
52
  # Indexes and constraints go before the columns they're on, and come back
23
53
  # after the columns they need.
24
54
  # @rbs (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns,
25
- # Skyward::ORM::Catalog::Table table, Skyward::ORM::_Adapter adapter,
55
+ # Skyward::ORM::Catalog::Table table, Array[Skyward::ORM::Catalog::Table] tables, Skyward::ORM::_Adapter adapter,
26
56
  # ^(Symbol table, Symbol from, Symbol to) -> bool rename) -> Skyward::ORM::Migrations::AlterTable?
27
- def altered: (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns, Skyward::ORM::Catalog::Table table, Skyward::ORM::_Adapter adapter, ^(Symbol table, Symbol from, Symbol to) -> bool rename) -> Skyward::ORM::Migrations::AlterTable?
57
+ def altered: (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns, Skyward::ORM::Catalog::Table table, Array[Skyward::ORM::Catalog::Table] tables, Skyward::ORM::_Adapter adapter, ^(Symbol table, Symbol from, Symbol to) -> bool rename) -> Skyward::ORM::Migrations::AlterTable?
28
58
 
29
59
  # The indexes to drop and to add. One is compared by the columns it will
30
60
  # have after any rename, and dropped as the database has it.
@@ -34,12 +64,15 @@ module Skyward::ORM::Migrations::Diff
34
64
  # @rbs return: [Array[Skyward::ORM::Migrations::edit], Array[Skyward::ORM::Migrations::edit]]
35
65
  def indexes: (singleton(Skyward::ORM::Record) klass, Skyward::ORM::Catalog::Table table, Hash[Symbol, Symbol] renamed) -> [ Array[Skyward::ORM::Migrations::edit], Array[Skyward::ORM::Migrations::edit] ]
36
66
 
37
- # The constraints to drop and to add, compared as indexes are. A new
38
- # column's own constraints are part of its definition.
67
+ # The constraints to drop, to rename and to add, compared as indexes are. A
68
+ # foreign key or unique constraint the class declares that the table has
69
+ # under another name is renamed, from the first one if it has two, and the
70
+ # other is dropped. A new column's own constraints are part of its definition.
39
71
  # @rbs (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns,
40
72
  # Skyward::ORM::Catalog::Table table, Hash[Symbol, Symbol] renamed, Array[Skyward::ORM::Tables::Column] new_columns)
41
- # -> [Array[Skyward::ORM::Migrations::edit], Array[Skyward::ORM::Migrations::edit]]
42
- def constraints: (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns, Skyward::ORM::Catalog::Table table, Hash[Symbol, Symbol] renamed, Array[Skyward::ORM::Tables::Column] new_columns) -> [ Array[Skyward::ORM::Migrations::edit], Array[Skyward::ORM::Migrations::edit] ]
73
+ # -> [Array[Skyward::ORM::Migrations::edit], Array[Skyward::ORM::Migrations::edit],
74
+ # Array[Skyward::ORM::Migrations::edit]]
75
+ def constraints: (singleton(Skyward::ORM::Record) klass, Array[Skyward::ORM::Tables::Column] columns, Skyward::ORM::Catalog::Table table, Hash[Symbol, Symbol] renamed, Array[Skyward::ORM::Tables::Column] new_columns) -> [ Array[Skyward::ORM::Migrations::edit], Array[Skyward::ORM::Migrations::edit], Array[Skyward::ORM::Migrations::edit] ]
43
76
 
44
77
  # Each column that went is asked about each new one of a compatible type, in
45
78
  # order, until one is a rename. A column it renames to isn't asked about again.
@@ -47,7 +80,8 @@ module Skyward::ORM::Migrations::Diff
47
80
  # Skyward::ORM::_Adapter adapter, ^(Symbol table, Symbol from, Symbol to) -> bool rename) -> Hash[Symbol, Symbol]
48
81
  def renames: (Symbol table, Array[Skyward::ORM::Catalog::Column] removed, Array[Skyward::ORM::Tables::Column] added, Skyward::ORM::_Adapter adapter, ^(Symbol table, Symbol from, Symbol to) -> bool rename) -> Hash[Symbol, Symbol]
49
82
 
50
- # An untyped column has no type or nullability to compare.
83
+ # An untyped column has no type or nullability to compare, and a generated
84
+ # one no default.
51
85
  # @rbs klass: singleton(Skyward::ORM::Record)
52
86
  # @rbs column: Skyward::ORM::Tables::Column
53
87
  # @rbs had: Skyward::ORM::Catalog::Column
@@ -55,16 +89,37 @@ module Skyward::ORM::Migrations::Diff
55
89
  # @rbs return: Array[Skyward::ORM::Migrations::edit]
56
90
  def changed: (singleton(Skyward::ORM::Record) klass, Skyward::ORM::Tables::Column column, Skyward::ORM::Catalog::Column had, Skyward::ORM::_Adapter adapter) -> Array[Skyward::ORM::Migrations::edit]
57
91
 
92
+ # PostgreSQL respells a jsonb default, as '{"a": 1}' for '{"a":1}', and a
93
+ # float array's, as '{1e+20}' for '{1.0e+20}', so a JSON or Array column's
94
+ # default is compared by value.
95
+ # @rbs (Skyward::ORM::Tables::Column column, String had, String wanted, Skyward::ORM::_Adapter adapter) -> bool
96
+ def same_default?: (Skyward::ORM::Tables::Column column, String had, String wanted, Skyward::ORM::_Adapter adapter) -> bool
97
+
98
+ # The value a string literal holds as the column reads it, in an Array so
99
+ # that JSON's null isn't taken for no value, or nil when it's an expression
100
+ # or the column can't read it.
101
+ # @rbs (Skyward::ORM::Tables::Column column, String default, Skyward::ORM::_Adapter adapter) -> [untyped]?
102
+ def value: (Skyward::ORM::Tables::Column column, String default, Skyward::ORM::_Adapter adapter) -> [ untyped ]?
103
+
58
104
  # Constraints are matched by name. SQLite can hold one with no name, which
59
- # matches the one its class declares on the same columns. PostgreSQL rewrites
60
- # a check's expression, and puts it on every column it mentions, so a check
61
- # is matched by its name alone. A reference is also matched by what it does
62
- # ON DELETE.
105
+ # matches the one its class declares that does what it does. PostgreSQL
106
+ # rewrites a check's expression, and puts it on every column it mentions, so
107
+ # a check is matched by its name alone.
63
108
  # @rbs had: Skyward::ORM::Catalog::Constraint
64
109
  # @rbs wanted: Skyward::ORM::Catalog::Constraint
65
110
  # @rbs return: bool
66
111
  def same?: (Skyward::ORM::Catalog::Constraint had, Skyward::ORM::Catalog::Constraint wanted) -> bool
67
112
 
113
+ # @rbs had: Skyward::ORM::Catalog::Constraint
114
+ # @rbs wanted: Skyward::ORM::Catalog::Constraint
115
+ # @rbs return: bool
116
+ def renamed?: (Skyward::ORM::Catalog::Constraint had, Skyward::ORM::Catalog::Constraint wanted) -> bool
117
+
118
+ # @rbs had: Skyward::ORM::Catalog::Constraint
119
+ # @rbs wanted: Skyward::ORM::Catalog::Constraint
120
+ # @rbs return: bool
121
+ def alike?: (Skyward::ORM::Catalog::Constraint had, Skyward::ORM::Catalog::Constraint wanted) -> bool
122
+
68
123
  # @rbs constraint: Skyward::ORM::Catalog::Constraint
69
124
  # @rbs return: String
70
125
  def on_delete: (Skyward::ORM::Catalog::Constraint constraint) -> String
@@ -76,6 +131,17 @@ module Skyward::ORM::Migrations::Diff
76
131
  # @rbs return: bool
77
132
  def same_index?: (Skyward::ORM::Catalog::Index had, Skyward::ORM::Catalog::Index wanted) -> bool
78
133
 
134
+ # @rbs constraint: Skyward::ORM::Catalog::Constraint
135
+ # @rbs tables: Array[Skyward::ORM::Catalog::Table]
136
+ # @rbs return: bool
137
+ def declarable?: (Skyward::ORM::Catalog::Constraint constraint, Array[Skyward::ORM::Catalog::Table] tables) -> bool
138
+
139
+ # A reference that names no columns is to its table's primary key.
140
+ # @rbs constraint: Skyward::ORM::Catalog::Constraint
141
+ # @rbs tables: Array[Skyward::ORM::Catalog::Table]
142
+ # @rbs return: bool
143
+ def to_primary_key?: (Skyward::ORM::Catalog::Constraint constraint, Array[Skyward::ORM::Catalog::Table] tables) -> bool
144
+
79
145
  # @rbs constraint: Skyward::ORM::Catalog::Constraint
80
146
  # @rbs added: Array[Skyward::ORM::Tables::Column]
81
147
  # @rbs return: bool
@@ -0,0 +1,16 @@
1
+ # Generated from lib/skyward/orm/migrations/rename_constraint.rb with RBS::Inline
2
+
3
+ module Skyward::ORM::Migrations
4
+ class RenameConstraint < Data
5
+ attr_reader from(): String
6
+
7
+ attr_reader to(): String
8
+
9
+ def self.new: (String from, String to) -> instance
10
+ | (from: String, to: String) -> instance
11
+
12
+ def self.members: () -> [ :from, :to ]
13
+
14
+ def members: () -> [ :from, :to ]
15
+ end
16
+ end
@@ -11,6 +11,8 @@ module Skyward::ORM::Migrations::Runner
11
11
 
12
12
  DOWN: Regexp
13
13
 
14
+ RAN_AT: Skyward::ORM::Tables::Column
15
+
14
16
  # @rbs path: String
15
17
  # @rbs return: Array[Migration]
16
18
  def read: (String path) -> Array[Migration]
@@ -54,6 +56,9 @@ module Skyward::ORM::Migrations::Runner
54
56
  # @rbs (Skyward::ORM::_Connection connection, Migration migration) { () -> (bool | Failed) } -> (bool | Failed)
55
57
  def run_locked: (Skyward::ORM::_Connection connection, Migration migration) { () -> (bool | Failed) } -> (bool | Failed)
56
58
 
59
+ # @rbs (Skyward::ORM::_Adapter adapter, Skyward::ORM::_Connection connection) -> void
60
+ def end_migration: (Skyward::ORM::_Adapter adapter, Skyward::ORM::_Connection connection) -> void
61
+
57
62
  # SQLite ends the transaction itself on some failures, such as ON CONFLICT
58
63
  # ROLLBACK, and then ROLLBACK raises, though the outcome is already decided.
59
64
  # @rbs (Skyward::ORM::_Connection connection) -> void