dynamic_migrations 3.6.2 → 3.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/dynamic_migrations/active_record/migrators.rb +0 -1
- data/lib/dynamic_migrations/postgres/generator/column.rb +11 -3
- 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/table.rb +18 -1
- 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 +0 -1
- 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: ffc5194d0e153bdd70a23f5e5b83a3b916d06f1f0b27ea044f9dfab6ef0faa8f
|
4
|
+
data.tar.gz: 901bf23a5e92dfd68bc45fea4945aa7ac2930b4d7c2d1217196d3b16228076b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 464de1cbaffead85f9be5bb65c0146984d78c607a95d3ea2ba33293966eb5065f1542867b8667364388e54a06d50a8062919dc512324001b23d1f2fcd4e0ad62
|
7
|
+
data.tar.gz: 5d30a1b918c09e6d5206e1dd0c0c4963f0b23c0a92b4282c306b9465ed5825f3f0e321c76c274eaa4f465a6f02e907ec1864320ef26f9793e812e9bd0abaea82
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [3.6.4](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.3...v3.6.4) (2023-09-13)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* using active records standard disable/enable_extension, and create/drop schema methods ([4a73e5c](https://github.com/craigulliott/dynamic_migrations/commit/4a73e5c2d6642bdd9c5f61164a044bbed9032da9))
|
9
|
+
|
10
|
+
## [3.6.3](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.2...v3.6.3) (2023-09-13)
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* passing correct type when generating column migrations ([e345d56](https://github.com/craigulliott/dynamic_migrations/commit/e345d56cdb11bb965c71c251d82ce2087b416f47))
|
16
|
+
|
3
17
|
## [3.6.2](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.1...v3.6.2) (2023-09-13)
|
4
18
|
|
5
19
|
|
@@ -32,9 +32,17 @@ module DynamicMigrations
|
|
32
32
|
|
33
33
|
options_syntax = options.map { |k, v| "#{k}: #{v}" }.join(", ")
|
34
34
|
|
35
|
-
data_type = column.data_type
|
35
|
+
data_type = column.data_type.to_s
|
36
|
+
# if it's an array, then we need to remove the [] from the end
|
36
37
|
if column.array?
|
37
|
-
data_type =
|
38
|
+
data_type = data_type.sub(/\[\]\z/, "")
|
39
|
+
end
|
40
|
+
# if its a custom type (has special characters) then we need to quote it
|
41
|
+
# otherwise, present it as a symbol
|
42
|
+
data_type = if data_type.match?(/\A\w+\z/)
|
43
|
+
":#{data_type}"
|
44
|
+
else
|
45
|
+
"\"#{data_type}\""
|
38
46
|
end
|
39
47
|
|
40
48
|
add_fragment schema: column.table.schema,
|
@@ -43,7 +51,7 @@ module DynamicMigrations
|
|
43
51
|
object: column,
|
44
52
|
code_comment: code_comment,
|
45
53
|
migration: <<~RUBY
|
46
|
-
add_column :#{column.table.name}, :#{column.name},
|
54
|
+
add_column :#{column.table.name}, :#{column.name}, #{data_type}, #{options_syntax}
|
47
55
|
RUBY
|
48
56
|
end
|
49
57
|
|
@@ -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
|
@@ -88,6 +88,10 @@ module DynamicMigrations
|
|
88
88
|
options = {}
|
89
89
|
options[:null] = column.null
|
90
90
|
|
91
|
+
if column.array?
|
92
|
+
options[:array] = true
|
93
|
+
end
|
94
|
+
|
91
95
|
unless column.default.nil?
|
92
96
|
options[:default] = "\"#{column.default}\""
|
93
97
|
end
|
@@ -103,7 +107,20 @@ module DynamicMigrations
|
|
103
107
|
|
104
108
|
options_syntax = options.map { |k, v| "#{k}: #{v}" }.join(", ")
|
105
109
|
|
106
|
-
|
110
|
+
data_type = column.data_type.to_s
|
111
|
+
# if it's an array, then we need to remove the [] from the end
|
112
|
+
if column.array?
|
113
|
+
data_type = data_type.sub(/\[\]\z/, "")
|
114
|
+
end
|
115
|
+
# if its a custom type (has special characters) then we need to quote it
|
116
|
+
# otherwise, present it as a symbol
|
117
|
+
data_type = if data_type.match?(/\A\w+\z/)
|
118
|
+
":#{data_type}"
|
119
|
+
else
|
120
|
+
"\"#{data_type}\""
|
121
|
+
end
|
122
|
+
|
123
|
+
lines << "t.column #{data_type}, :#{column.name}, #{options_syntax}"
|
107
124
|
end
|
108
125
|
|
109
126
|
if timestamps.any?
|
@@ -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"
|
@@ -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.4
|
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
|