dynamic_migrations 3.6.1 → 3.6.3

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: a5f6a69d0ef49c88c5d4f7d1f3798e6a4272fccdad5e3e1c2f5887cf43e552a9
4
- data.tar.gz: c3faf73058b222ac2a7b10006022d8a08e8b311efad48481f3b64e204b0b3c33
3
+ metadata.gz: b60f89c7a66fe00d71581049f4886a5baa6ca89255dbb47315637bfa6fc5d9be
4
+ data.tar.gz: cde91d7188a94a3443c8331c6efa9e966a8e86fee236fb156adc577cfebbc156
5
5
  SHA512:
6
- metadata.gz: 1be6d466691eaf92f8b999de32a400cb1e14067618cb9ffe429275110675a516aa2797bc3368ce1d0a4aa66d4021044555cc2e54cb31d1a7290f89b72ae93ce4
7
- data.tar.gz: 851125f34e2df74a7457d620372321a011459777a30543775eebdda6fcaf7c0cfe5b66e41b1c118bf4d6a029c4f99c8f99150032fa03fc97c18fa3656cd84c54
6
+ metadata.gz: 2a047c9a0d916de3bd28cd8bf41cbb91d7603eb562d68a5e5a9c099a1418d25a9756787ed735fe0badd8de712418366567b3af65cb86cf1c6b3c3898390c8415
7
+ data.tar.gz: 6ff07ad81f425dc6c2804e4dc38c36ee4122ff89b449fa9c98065213ca2730f0cf3f4e3c014f465482835c54d6d3f52453a0e0b463a694517b6c0c039e0bb3e9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.6.3](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.2...v3.6.3) (2023-09-13)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * passing correct type when generating column migrations ([e345d56](https://github.com/craigulliott/dynamic_migrations/commit/e345d56cdb11bb965c71c251d82ce2087b416f47))
9
+
10
+ ## [3.6.2](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.1...v3.6.2) (2023-09-13)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * don't generate columns separately for migrations if also generating the table (as they are already included in the table definition) ([b6f748c](https://github.com/craigulliott/dynamic_migrations/commit/b6f748c8e72aaab12d32243f6a007d03707041da))
16
+
3
17
  ## [3.6.1](https://github.com/craigulliott/dynamic_migrations/compare/v3.6.0...v3.6.1) (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 = "\"#{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}, :#{data_type}, #{options_syntax}
54
+ add_column :#{column.table.name}, :#{column.name}, #{data_type}, #{options_syntax}
47
55
  RUBY
48
56
  end
49
57
 
@@ -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
- lines << "t.#{column.data_type} :#{column.name}, #{options_syntax}"
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?
@@ -26,7 +26,7 @@ module DynamicMigrations
26
26
 
27
27
  # we process everything else after we create the table, because the other
28
28
  # database objects are dependent on the table
29
- process_dependents schema_name, table_name, configuration_table, {}
29
+ process_dependents schema_name, table_name, configuration_table, {}, skip_columns: true
30
30
 
31
31
  # If the schema exists in the database but not in the configuration
32
32
  # then we need to delete it.
@@ -60,8 +60,11 @@ module DynamicMigrations
60
60
  end
61
61
  end
62
62
 
63
- def process_dependents schema_name, table_name, configuration_table, database_table
64
- process_columns schema_name, table_name, configuration_table[:columns] || {}, database_table[:columns] || {}
63
+ def process_dependents schema_name, table_name, configuration_table, database_table, skip_columns: false
64
+ # we skip columns if we are processing the table for the first time, as they are processed within the table creation
65
+ unless skip_columns
66
+ process_columns schema_name, table_name, configuration_table[:columns] || {}, database_table[:columns] || {}
67
+ end
65
68
  process_foreign_key_constraints schema_name, table_name, configuration_table[:foreign_key_constraints] || {}, database_table[:foreign_key_constraints] || {}
66
69
  process_indexes schema_name, table_name, configuration_table[:indexes] || {}, database_table[:indexes] || {}
67
70
  process_triggers schema_name, table_name, configuration_table[:triggers] || {}, database_table[:triggers] || {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamicMigrations
4
- VERSION = "3.6.1"
4
+ VERSION = "3.6.3"
5
5
  end
@@ -14,7 +14,7 @@ module DynamicMigrations
14
14
  def process_tables: (Symbol schema_name, untyped configuration_tables, untyped database_tables) -> void
15
15
  def process_table: (Symbol schema_name, Symbol table_name, untyped configuration_table, untyped database_table) -> void
16
16
  # this method comes from the Columns module
17
- def process_dependents: (Symbol schema_name, Symbol table_name, untyped configuration_columns, untyped database_columns) -> void
17
+ def process_dependents: (Symbol schema_name, Symbol table_name, untyped configuration_columns, untyped database_columns, ?skip_columns: bool) -> void
18
18
  def process_columns: (Symbol schema_name, Symbol table_name, untyped configuration_columns, untyped database_columns) -> void
19
19
  def process_foreign_key_constraints: (Symbol schema_name, Symbol table_name, untyped configuration_foreign_key_constraints, untyped database_foreign_key_constraints) -> void
20
20
  def process_indexes: (Symbol schema_name, Symbol table_name, untyped configuration_indexes, untyped database_indexes) -> void
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.1
4
+ version: 3.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Ulliott