dynamic_migrations 3.6.3 → 3.6.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/dynamic_migrations/active_record/migrators.rb +16 -12
- data/lib/dynamic_migrations/postgres/generator/database_migration.rb +4 -2
- data/lib/dynamic_migrations/postgres/generator/extension.rb +6 -6
- data/lib/dynamic_migrations/postgres/generator/migration.rb +6 -6
- data/lib/dynamic_migrations/postgres/generator/schema.rb +4 -4
- data/lib/dynamic_migrations/postgres/generator/schema_migration.rb +0 -3
- data/lib/dynamic_migrations/postgres/generator.rb +3 -2
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/extensions.rb +2 -2
- data/lib/dynamic_migrations/version.rb +1 -1
- data/lib/dynamic_migrations.rb +0 -1
- data/sig/dynamic_migrations/active_record/migrators.rbs +12 -11
- data/sig/dynamic_migrations/postgres/generator/extension.rbs +2 -2
- metadata +1 -3
- data/lib/dynamic_migrations/active_record/migrators/schema.rb +0 -21
- data/sig/dynamic_migrations/active_record/migrators/schema.rbs +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fc1e5f220706376e73d84dc6f78acbb549f745a45c70d89e8335f540e44ef5f
|
4
|
+
data.tar.gz: 5532ce24fbcc66d9d0eeb765b686f303af60e871ae371437953d88170ea51898
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bf89b66978b604919aaf1892df850a8679d611d4052ec904970fd0859879fefb3ae0878159243af80ec4b2484207a29f74248a44487baa3c27fafa6b5c51cba
|
7
|
+
data.tar.gz: 367a8f6fff5a9a5e869c8720e662745d755972e225e0145001b4126856c45e2ad75e9e783a2277590932abac2b39db42305abed509dda51c7c0dbed4a4e85d7b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [3.6.5](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.4...v3.6.5) (2023-09-13)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* setting current schema on the migration class instead of the shared module ([28bc2ca](https://github.com/craigulliott/dynamic_migrations/commit/28bc2ca454883696665804c8596fc3b19ce31bb4))
|
9
|
+
|
10
|
+
## [3.6.4](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.3...v3.6.4) (2023-09-13)
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* using active records standard disable/enable_extension, and create/drop schema methods ([4a73e5c](https://github.com/craigulliott/dynamic_migrations/commit/4a73e5c2d6642bdd9c5f61164a044bbed9032da9))
|
16
|
+
|
3
17
|
## [3.6.3](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.2...v3.6.3) (2023-09-13)
|
4
18
|
|
5
19
|
|
@@ -21,7 +21,6 @@ module DynamicMigrations
|
|
21
21
|
class MissingFunctionBlockError < StandardError
|
22
22
|
end
|
23
23
|
|
24
|
-
include Schema
|
25
24
|
include Validation
|
26
25
|
include ForeignKeyConstraint
|
27
26
|
include Table
|
@@ -32,19 +31,24 @@ module DynamicMigrations
|
|
32
31
|
include Trigger
|
33
32
|
include Enum
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
# DynamicMigrations::ActiveRecord::Migrators.set_schema_name :schema_name
|
38
|
-
def self.schema_name
|
39
|
-
@current_schema
|
34
|
+
def self.included(base)
|
35
|
+
base.extend(ClassMethods)
|
40
36
|
end
|
41
37
|
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
module ClassMethods
|
39
|
+
# The schema name should be set on the migration class before the migration
|
40
|
+
# is run
|
41
|
+
def schema_name
|
42
|
+
@current_schema
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
45
|
+
def set_schema_name schema_name
|
46
|
+
@current_schema = schema_name.to_sym
|
47
|
+
end
|
48
|
+
|
49
|
+
def clear_schema_name
|
50
|
+
@current_schema = nil
|
51
|
+
end
|
48
52
|
end
|
49
53
|
|
50
54
|
def quote string
|
@@ -53,7 +57,7 @@ module DynamicMigrations
|
|
53
57
|
|
54
58
|
# this method is made available on the final migration class
|
55
59
|
def schema_name
|
56
|
-
sn =
|
60
|
+
sn = self.class.schema_name
|
57
61
|
if sn.nil?
|
58
62
|
raise SchemaNameNotSetError
|
59
63
|
end
|
@@ -6,8 +6,10 @@ module DynamicMigrations
|
|
6
6
|
# note that removals come before additions, and that the order here optomizes
|
7
7
|
# for dependencies (i.e. columns have to be created before indexes are added and
|
8
8
|
# triggers are removed before functions are dropped)
|
9
|
-
add_structure_template [:
|
10
|
-
add_structure_template [:
|
9
|
+
add_structure_template [:disable_extension], "Drop Extension"
|
10
|
+
add_structure_template [:enable_extension], "Create Extension"
|
11
|
+
add_structure_template [:drop_schema], "Drop this schema"
|
12
|
+
add_structure_template [:create_schema], "Create this schema"
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -2,23 +2,23 @@ module DynamicMigrations
|
|
2
2
|
module Postgres
|
3
3
|
class Generator
|
4
4
|
module Extension
|
5
|
-
def
|
5
|
+
def enable_extension extension_name, code_comment = nil
|
6
6
|
# no table or schema name for this fragment (it is executed at the database level)
|
7
|
-
add_fragment migration_method: :
|
7
|
+
add_fragment migration_method: :enable_extension,
|
8
8
|
object: extension_name,
|
9
9
|
code_comment: code_comment,
|
10
10
|
migration: <<~RUBY
|
11
|
-
|
11
|
+
enable_extension "#{extension_name}"
|
12
12
|
RUBY
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def disable_extension extension_name, code_comment = nil
|
16
16
|
# no table or schema name for this fragment (it is executed at the database level)
|
17
|
-
add_fragment migration_method: :
|
17
|
+
add_fragment migration_method: :disable_extension,
|
18
18
|
object: extension_name,
|
19
19
|
code_comment: code_comment,
|
20
20
|
migration: <<~RUBY
|
21
|
-
|
21
|
+
disable_extension "#{extension_name}"
|
22
22
|
RUBY
|
23
23
|
end
|
24
24
|
end
|
@@ -144,10 +144,10 @@ module DynamicMigrations
|
|
144
144
|
raise NoFragmentsError if fragments.empty?
|
145
145
|
|
146
146
|
if fragments_for_method? :create_schema
|
147
|
-
:"create_#{
|
147
|
+
:"create_#{fragments.first&.object_name}_schema"
|
148
148
|
|
149
149
|
elsif fragments_for_method? :drop_schema
|
150
|
-
:"drop_#{
|
150
|
+
:"drop_#{fragments.first&.object_name}_schema"
|
151
151
|
|
152
152
|
elsif fragments_for_method? :create_table
|
153
153
|
:"create_#{first_fragment_using_migration_method(:create_table).table_name}"
|
@@ -164,11 +164,11 @@ module DynamicMigrations
|
|
164
164
|
elsif all_fragments_for_method? [:create_enum, :add_enum_values, :drop_enum, :set_enum_comment, :remove_enum_comment]
|
165
165
|
:enums
|
166
166
|
|
167
|
-
elsif all_fragments_for_method? [:
|
168
|
-
(@fragments.count > 1) ? :
|
167
|
+
elsif all_fragments_for_method? [:enable_extension]
|
168
|
+
(@fragments.count > 1) ? :enable_extensions : :"create_#{fragments.first&.object_name}_extension"
|
169
169
|
|
170
|
-
elsif all_fragments_for_method? [:
|
171
|
-
(@fragments.count > 1) ? :
|
170
|
+
elsif all_fragments_for_method? [:disable_extension]
|
171
|
+
(@fragments.count > 1) ? :disable_extensions : :"drop_#{fragments.first&.object_name}_extension"
|
172
172
|
|
173
173
|
elsif @fragments.first&.table_name
|
174
174
|
:"changes_for_#{@fragments.first&.table_name}"
|
@@ -3,8 +3,8 @@ module DynamicMigrations
|
|
3
3
|
class Generator
|
4
4
|
module Schema
|
5
5
|
def create_schema schema, code_comment = nil
|
6
|
-
|
7
|
-
|
6
|
+
# no table or schema name for this fragment (it is executed at the database level)
|
7
|
+
add_fragment migration_method: :create_schema,
|
8
8
|
object: schema,
|
9
9
|
code_comment: code_comment,
|
10
10
|
migration: <<~RUBY
|
@@ -13,8 +13,8 @@ module DynamicMigrations
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def drop_schema schema, code_comment = nil
|
16
|
-
|
17
|
-
|
16
|
+
# no table or schema name for this fragment (it is executed at the database level)
|
17
|
+
add_fragment migration_method: :drop_schema,
|
18
18
|
object: schema,
|
19
19
|
code_comment: code_comment,
|
20
20
|
migration: <<~RUBY
|
@@ -8,12 +8,9 @@ module DynamicMigrations
|
|
8
8
|
# triggers are removed before functions are dropped)
|
9
9
|
add_structure_template [:remove_function_comment, :drop_function], "Remove Functions"
|
10
10
|
add_structure_template [:remove_enum_comment, :drop_enum], "Drop Enums"
|
11
|
-
add_structure_template [:drop_schema], "Drop this schema"
|
12
11
|
add_structure_template [:create_enum, :add_enum_values, :set_enum_comment], "Enums"
|
13
|
-
add_structure_template [:create_schema], "Create this schema"
|
14
12
|
add_structure_template [:create_function], "Functions"
|
15
13
|
add_structure_template [:update_function, :set_function_comment], "Update Functions"
|
16
|
-
add_structure_template [:create_extension, :drop_extension], "Extensions"
|
17
14
|
|
18
15
|
def initialize schema_name
|
19
16
|
raise MissingRequiredSchemaName unless schema_name
|
@@ -72,10 +72,11 @@ module DynamicMigrations
|
|
72
72
|
schema_migration = schema_migrations[:schema_migration] ||= SchemaMigration.new(schema_name)
|
73
73
|
schema_migration.add_fragment fragment
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
# migrations with no schema or table, are added to a database
|
76
|
+
# migration (these are really just creating/dropping schemas and extensions)
|
77
77
|
elsif schema_name.nil? && table_name.nil?
|
78
78
|
database_specific_migration.add_fragment fragment
|
79
|
+
|
79
80
|
else
|
80
81
|
raise UnprocessableFragmentError
|
81
82
|
end
|
data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/extensions.rb
CHANGED
@@ -12,13 +12,13 @@ module DynamicMigrations
|
|
12
12
|
# then we have to create it
|
13
13
|
if configuration_extension[:exists] == true && !database_extension[:exists]
|
14
14
|
# a migration to create the extension
|
15
|
-
@generator.
|
15
|
+
@generator.enable_extension extension_name
|
16
16
|
|
17
17
|
# if the extension exists in the database but not in the configuration
|
18
18
|
# then we need to delete it
|
19
19
|
elsif database_extension[:exists] == true && !configuration_extension[:exists]
|
20
20
|
# a migration to drop the extension
|
21
|
-
@generator.
|
21
|
+
@generator.disable_extension extension_name
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/lib/dynamic_migrations.rb
CHANGED
@@ -87,7 +87,6 @@ require "dynamic_migrations/postgres/generator/schema_migration"
|
|
87
87
|
require "dynamic_migrations/postgres/generator/table_migration"
|
88
88
|
require "dynamic_migrations/postgres/generator/migration_dependency_sorter"
|
89
89
|
|
90
|
-
require "dynamic_migrations/active_record/migrators/schema"
|
91
90
|
require "dynamic_migrations/active_record/migrators/validation"
|
92
91
|
require "dynamic_migrations/active_record/migrators/foreign_key_constraint"
|
93
92
|
require "dynamic_migrations/active_record/migrators/unique_constraint"
|
@@ -1,12 +1,6 @@
|
|
1
|
-
# TypeProf 0.21.7
|
2
|
-
|
3
|
-
# Classes
|
4
1
|
module DynamicMigrations
|
5
2
|
module ActiveRecord
|
6
3
|
module Migrators
|
7
|
-
self.@current_schema: nil
|
8
|
-
|
9
|
-
include Schema
|
10
4
|
include Validation
|
11
5
|
include ForeignKeyConstraint
|
12
6
|
include Column
|
@@ -15,11 +9,10 @@ module DynamicMigrations
|
|
15
9
|
include Function
|
16
10
|
include Trigger
|
17
11
|
|
18
|
-
def self.
|
19
|
-
def
|
20
|
-
def
|
21
|
-
def self.
|
22
|
-
def schema_name: -> nil
|
12
|
+
def self.included: (untyped base) -> void
|
13
|
+
def quote: (untyped string) -> String
|
14
|
+
def schema_name: -> Symbol
|
15
|
+
def self.schema_name: -> Symbol
|
23
16
|
|
24
17
|
# this methods comes from active record once the module has been included
|
25
18
|
def connection: -> untyped
|
@@ -32,6 +25,14 @@ module DynamicMigrations
|
|
32
25
|
|
33
26
|
class MissingFunctionBlockError < StandardError
|
34
27
|
end
|
28
|
+
|
29
|
+
module ClassMethods
|
30
|
+
@current_schema: Symbol?
|
31
|
+
|
32
|
+
def schema_name: -> Symbol?
|
33
|
+
def set_schema_name: (untyped schema_name) -> void
|
34
|
+
def clear_schema_name: -> void
|
35
|
+
end
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -5,8 +5,8 @@ module DynamicMigrations
|
|
5
5
|
module Postgres
|
6
6
|
class Generator
|
7
7
|
module Extension
|
8
|
-
def
|
9
|
-
def
|
8
|
+
def enable_extension: (Symbol extension_name, ?String? code_comment) -> Fragment
|
9
|
+
def disable_extension: (Symbol extension_name, ?String? code_comment) -> Fragment
|
10
10
|
|
11
11
|
# these come from the generator object (which this module is included into)
|
12
12
|
def add_fragment: (migration_method: Symbol, object: untyped, migration: String, ?schema: Server::Database::Schema?, ?table: Server::Database::Schema::Table?, ?code_comment: String?, ?dependent_table: Server::Database::Schema::Table?) -> untyped
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Ulliott
|
@@ -71,7 +71,6 @@ files:
|
|
71
71
|
- lib/dynamic_migrations/active_record/migrators/foreign_key_constraint.rb
|
72
72
|
- lib/dynamic_migrations/active_record/migrators/function.rb
|
73
73
|
- lib/dynamic_migrations/active_record/migrators/index.rb
|
74
|
-
- lib/dynamic_migrations/active_record/migrators/schema.rb
|
75
74
|
- lib/dynamic_migrations/active_record/migrators/table.rb
|
76
75
|
- lib/dynamic_migrations/active_record/migrators/trigger.rb
|
77
76
|
- lib/dynamic_migrations/active_record/migrators/unique_constraint.rb
|
@@ -163,7 +162,6 @@ files:
|
|
163
162
|
- sig/dynamic_migrations/active_record/migrators/foreign_key_constraint.rbs
|
164
163
|
- sig/dynamic_migrations/active_record/migrators/function.rbs
|
165
164
|
- sig/dynamic_migrations/active_record/migrators/index.rbs
|
166
|
-
- sig/dynamic_migrations/active_record/migrators/schema.rbs
|
167
165
|
- sig/dynamic_migrations/active_record/migrators/table.rbs
|
168
166
|
- sig/dynamic_migrations/active_record/migrators/trigger.rbs
|
169
167
|
- sig/dynamic_migrations/active_record/migrators/unique_constraint.rbs
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module DynamicMigrations
|
2
|
-
module ActiveRecord
|
3
|
-
module Migrators
|
4
|
-
module Schema
|
5
|
-
def create_schema
|
6
|
-
# schema_name was not provided to this method, it comes from the migration class
|
7
|
-
execute <<~SQL
|
8
|
-
CREATE SCHEMA #{schema_name};
|
9
|
-
SQL
|
10
|
-
end
|
11
|
-
|
12
|
-
def drop_schema
|
13
|
-
# schema_name was not provided to this method, it comes from the migration class
|
14
|
-
execute <<~SQL
|
15
|
-
DROP SCHEMA #{schema_name};
|
16
|
-
SQL
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# TypeProf 0.21.7
|
2
|
-
|
3
|
-
# Classes
|
4
|
-
module DynamicMigrations
|
5
|
-
module ActiveRecord
|
6
|
-
module Migrators
|
7
|
-
module Schema
|
8
|
-
def create_schema: () -> void
|
9
|
-
def drop_schema: () -> void
|
10
|
-
|
11
|
-
# stubbing these out, as they are available on the module which includes this module
|
12
|
-
def execute: (String sql) -> void
|
13
|
-
def schema_name: () -> Symbol
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|