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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b60f89c7a66fe00d71581049f4886a5baa6ca89255dbb47315637bfa6fc5d9be
4
- data.tar.gz: cde91d7188a94a3443c8331c6efa9e966a8e86fee236fb156adc577cfebbc156
3
+ metadata.gz: 2fc1e5f220706376e73d84dc6f78acbb549f745a45c70d89e8335f540e44ef5f
4
+ data.tar.gz: 5532ce24fbcc66d9d0eeb765b686f303af60e871ae371437953d88170ea51898
5
5
  SHA512:
6
- metadata.gz: 2a047c9a0d916de3bd28cd8bf41cbb91d7603eb562d68a5e5a9c099a1418d25a9756787ed735fe0badd8de712418366567b3af65cb86cf1c6b3c3898390c8415
7
- data.tar.gz: 6ff07ad81f425dc6c2804e4dc38c36ee4122ff89b449fa9c98065213ca2730f0cf3f4e3c014f465482835c54d6d3f52453a0e0b463a694517b6c0c039e0bb3e9
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
- # The schema name should be set before the migrations for
36
- # each schema's migrations are run. This is done by:
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
- def self.set_schema_name schema_name
43
- @current_schema = schema_name.to_sym
44
- end
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
- def self.clear_schema_name
47
- @current_schema = nil
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 = Migrators.schema_name
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 [:create_extension], "Create Extension"
10
- add_structure_template [:drop_extension], "Drop Extension"
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 create_extension extension_name, code_comment = nil
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: :create_extension,
7
+ add_fragment migration_method: :enable_extension,
8
8
  object: extension_name,
9
9
  code_comment: code_comment,
10
10
  migration: <<~RUBY
11
- create_extension "#{extension_name}"
11
+ enable_extension "#{extension_name}"
12
12
  RUBY
13
13
  end
14
14
 
15
- def drop_extension extension_name, code_comment = nil
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: :drop_extension,
17
+ add_fragment migration_method: :disable_extension,
18
18
  object: extension_name,
19
19
  code_comment: code_comment,
20
20
  migration: <<~RUBY
21
- drop_extension "#{extension_name}"
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_#{first_fragment_using_migration_method(:create_schema).schema_name}_schema"
147
+ :"create_#{fragments.first&.object_name}_schema"
148
148
 
149
149
  elsif fragments_for_method? :drop_schema
150
- :"drop_#{first_fragment_using_migration_method(:drop_schema).schema_name}_schema"
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? [:create_extension]
168
- (@fragments.count > 1) ? :create_extensions : :"create_#{fragments.first&.object_name}_extension"
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? [:drop_extension]
171
- (@fragments.count > 1) ? :drop_extensions : :"drop_#{fragments.first&.object_name}_extension"
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
- add_fragment schema: schema,
7
- migration_method: :create_schema,
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
- add_fragment schema: schema,
17
- migration_method: :drop_schema,
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
- # migrations with no schema or table, are added to a database
76
- # migration (these re really just creating/dropping extensions)
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
@@ -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.create_extension extension_name
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.drop_extension extension_name
21
+ @generator.disable_extension extension_name
22
22
  end
23
23
  end
24
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamicMigrations
4
- VERSION = "3.6.3"
4
+ VERSION = "3.6.5"
5
5
  end
@@ -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.schema_name: -> nil
19
- def self.set_schema_name: (untyped schema_name) -> untyped
20
- def self.clear_schema_name: -> nil
21
- def self.included: (untyped klass) -> untyped
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 create_extension: (Symbol extension_name, ?String? code_comment) -> Fragment
9
- def drop_extension: (Symbol extension_name, ?String? code_comment) -> Fragment
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.3
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