dynamic_migrations 3.8.2 → 3.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/extensions.rb +4 -0
  4. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/enums.rb +13 -0
  5. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/functions.rb +15 -0
  6. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/columns.rb +15 -0
  7. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/foreign_key_constraints.rb +15 -0
  8. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/indexes.rb +15 -0
  9. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/primary_key.rb +10 -0
  10. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/triggers.rb +15 -0
  11. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/unique_constraints.rb +15 -0
  12. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/validations.rb +15 -0
  13. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables.rb +11 -0
  14. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas.rb +4 -0
  15. data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations.rb +10 -0
  16. data/lib/dynamic_migrations/postgres/server/database/differences.rb +58 -9
  17. data/lib/dynamic_migrations/version.rb +1 -1
  18. data/lib/dynamic_migrations.rb +3 -0
  19. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/extensions.rbs +3 -0
  20. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/enums.rbs +2 -0
  21. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/functions.rbs +2 -0
  22. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/columns.rbs +2 -0
  23. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/foreign_key_constraints.rbs +2 -0
  24. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/indexes.rbs +2 -0
  25. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/primary_key.rbs +2 -0
  26. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/triggers.rbs +2 -0
  27. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/unique_constraints.rbs +2 -0
  28. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/validations.rbs +2 -0
  29. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables.rbs +2 -0
  30. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas.rbs +3 -0
  31. data/sig/dynamic_migrations/postgres/server/database/differences/to_migrations.rbs +2 -0
  32. data/sig/dynamic_migrations/postgres/server/database/differences.rbs +8 -11
  33. data/sig/logging.rbs +11 -0
  34. metadata +16 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2641592d2902b2b4db711882300e45157cf45df12d3f19ceea84ff97e13f6fab
4
- data.tar.gz: d6eb83a0f1d0631acc1474d18305e0828688210f7008dbddb460dc1b2cfaf668
3
+ metadata.gz: '08737568ccf7605e0a4d404063b7e1708e67c0ed96ab9f091bb72db627c0d50b'
4
+ data.tar.gz: 404f7bd4816def6c379a9277ec9c06ad4f58d188d3911f4ca9e9c1a38cf301f8
5
5
  SHA512:
6
- metadata.gz: 48130e442efa9a4e2ab9763fe8e0cb1f35bca56691361e0d3c350813e89c31e1445f59ff76b981e560eb521e8dfb72822ac80c04c738203b62237ccc9690ecc1
7
- data.tar.gz: 0a40ea04a41e2f072fe0f8ae9a163a1989c0e8c752b7078491ae5b75bbe18cfc3d3eebd777a61de2b4372297e78c54539d3a449b11a76771c19a86370d5fe588
6
+ metadata.gz: a403e1da441c1625e89034f07141d48c15fa07953404638795c2c11d58c79e26468f7b4b9070a37d18d6d62a91f069950b4d9ed824c6404071cee59fd3627d35
7
+ data.tar.gz: 3df74c476b5d84f8b98f774a69223934823670201649bf35f3aa5a6620738c0fba046bb56ac2e8139364a39ac5a6c4cbdcea547b2cf9625bf45f570261038b80
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.8.3](https://github.com/craigulliott/dynamic_migrations/compare/v3.8.2...v3.8.3) (2023-10-06)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * adding logging ([1387a75](https://github.com/craigulliott/dynamic_migrations/commit/1387a7535db242570b2b9fa60730d6bd73edb265))
9
+
3
10
  ## [3.8.2](https://github.com/craigulliott/dynamic_migrations/compare/v3.8.1...v3.8.2) (2023-10-06)
4
11
 
5
12
 
@@ -11,15 +11,19 @@ module DynamicMigrations
11
11
  # if the extension exists in the configuration but not in the database
12
12
  # then we have to create it
13
13
  if configuration_extension[:exists] == true && !database_extension[:exists]
14
+ log.info "Extension `#{extension_name}` exists in configuration but not in the database"
14
15
  # a migration to create the extension
15
16
  @generator.enable_extension extension_name
16
17
 
17
18
  # if the extension exists in the database but not in the configuration
18
19
  # then we need to delete it
19
20
  elsif database_extension[:exists] == true && !configuration_extension[:exists]
21
+ log.info "Extension `#{extension_name}` exists in database but not in the configuration"
20
22
  # a migration to drop the extension
21
23
  if Postgres.remove_unused_extensions?
22
24
  @generator.disable_extension extension_name
25
+ else
26
+ log.warn "Skipping removal of extension `#{extension_name}` due to configuration setting"
23
27
  end
24
28
  end
25
29
  end
@@ -10,8 +10,10 @@ module DynamicMigrations
10
10
  module Enums
11
11
  def process_enums schema_name, configuration_enums, database_enums
12
12
  # process all the enums
13
+ log.info " Processing tables..."
13
14
  enum_names = (configuration_enums.keys + database_enums.keys).uniq
14
15
  enum_names.each do |enum_name|
16
+ log.info " Processing table #{enum_name}..."
15
17
  process_enum schema_name, enum_name, configuration_enums[enum_name] || {}, database_enums[enum_name] || {}
16
18
  end
17
19
  end
@@ -20,6 +22,8 @@ module DynamicMigrations
20
22
  # If the enum exists in the configuration but not in the database
21
23
  # then we have to create it.
22
24
  if configuration_enum[:exists] == true && !database_enum[:exists]
25
+ log.info " Enum `#{enum_name}` exists in configuration but not in the database"
26
+
23
27
  # a migration to create the enum
24
28
  enum = @database.configured_schema(schema_name).enum(enum_name)
25
29
  @generator.create_enum enum
@@ -31,6 +35,8 @@ module DynamicMigrations
31
35
  # If the schema exists in the database but not in the configuration
32
36
  # then we need to delete it.
33
37
  elsif database_enum[:exists] == true && !configuration_enum[:exists]
38
+ log.info " Enum `#{enum_name}` exists in database but not in the configuration"
39
+
34
40
  # a migration to create the enum
35
41
  enum = @database.loaded_schema(schema_name).enum(enum_name)
36
42
  @generator.drop_enum enum
@@ -38,6 +44,9 @@ module DynamicMigrations
38
44
  # If the enum exists in both the configuration and database representations
39
45
  # but the values is different then we need to update the values.
40
46
  elsif configuration_enum[:values][:matches] == false
47
+ log.info " Enum `#{enum_name}` exists in both configuration and the database"
48
+
49
+ log.info " Enum `#{enum_name}` values are different"
41
50
  original_enum = @database.loaded_schema(schema_name).enum(enum_name)
42
51
  updated_enum = @database.configured_schema(schema_name).enum(enum_name)
43
52
  @generator.update_enum original_enum, updated_enum
@@ -45,8 +54,10 @@ module DynamicMigrations
45
54
  if configuration_enum[:description][:matches] == false
46
55
  # if the description was removed
47
56
  if configuration_enum[:description].nil?
57
+ log.info " Enum `#{enum_name}` description exists in database but not in the configuration"
48
58
  @generator.remove_enum_comment updated_enum
49
59
  else
60
+ log.info " Enum `#{enum_name}` description does not match"
50
61
  @generator.set_enum_comment updated_enum
51
62
  end
52
63
  end
@@ -57,8 +68,10 @@ module DynamicMigrations
57
68
  enum = @database.configured_schema(schema_name).enum(enum_name)
58
69
  # if the description was removed
59
70
  if configuration_enum[:description].nil?
71
+ log.info " Enum `#{enum_name}` description exists in database but not in the configuration"
60
72
  @generator.remove_enum_comment enum
61
73
  else
74
+ log.info " Enum `#{enum_name}` description does not match"
62
75
  @generator.set_enum_comment enum
63
76
  end
64
77
  end
@@ -10,8 +10,10 @@ module DynamicMigrations
10
10
  module Functions
11
11
  def process_functions schema_name, configuration_functions, database_functions
12
12
  # process all the functions
13
+ log.info " Processing Functions..."
13
14
  function_names = (configuration_functions.keys + database_functions.keys).uniq
14
15
  function_names.each do |function_name|
16
+ log.info " Processing Function #{function_name}..."
15
17
  process_function schema_name, function_name, configuration_functions[function_name] || {}, database_functions[function_name] || {}
16
18
  end
17
19
  end
@@ -20,6 +22,8 @@ module DynamicMigrations
20
22
  # If the function exists in the configuration but not in the database
21
23
  # then we have to create it.
22
24
  if configuration_function[:exists] == true && !database_function[:exists]
25
+ log.info " Function `#{function_name}` exists in configuration but not in the database"
26
+
23
27
  # a migration to create the function
24
28
  function = @database.configured_schema(schema_name).function(function_name)
25
29
  @generator.create_function function
@@ -27,6 +31,8 @@ module DynamicMigrations
27
31
  # If the schema exists in the database but not in the configuration
28
32
  # then we need to delete it.
29
33
  elsif database_function[:exists] == true && !configuration_function[:exists]
34
+ log.info " Function `#{function_name}` exists in database but not in the configuration"
35
+
30
36
  # a migration to create the function
31
37
  function = @database.loaded_schema(schema_name).function(function_name)
32
38
  @generator.drop_function function
@@ -34,14 +40,19 @@ module DynamicMigrations
34
40
  # If the function exists in both the configuration and database representations
35
41
  # but the definition is different then we need to update the definition.
36
42
  elsif configuration_function[:normalized_definition][:matches] == false
43
+ log.info " Function `#{function_name}` exists in both configuration and the database"
44
+
45
+ log.info " Function `#{function_name}` definition is different"
37
46
  function = @database.configured_schema(schema_name).function(function_name)
38
47
  @generator.update_function function
39
48
  # does the description also need to be updated
40
49
  if configuration_function[:description][:matches] == false
41
50
  # if the description was removed
42
51
  if configuration_function[:description].nil?
52
+ log.info " Function `#{function_name}` description exists in database but not in the configuration"
43
53
  @generator.remove_function_comment function
44
54
  else
55
+ log.info " Function `#{function_name}` description does not match"
45
56
  @generator.set_function_comment function
46
57
  end
47
58
  end
@@ -49,11 +60,15 @@ module DynamicMigrations
49
60
  # If the function exists in both the configuration and database representations
50
61
  # but the description is different then we need to update the description.
51
62
  elsif configuration_function[:description][:matches] == false
63
+ log.info " Function `#{function_name}` exists in both configuration and the database"
64
+
52
65
  function = @database.configured_schema(schema_name).function(function_name)
53
66
  # if the description was removed
54
67
  if configuration_function[:description].nil?
68
+ log.info " Function `#{function_name}` description exists in database but not in the configuration"
55
69
  @generator.remove_function_comment function
56
70
  else
71
+ log.info " Function `#{function_name}` description does not match"
57
72
  @generator.set_function_comment function
58
73
  end
59
74
  end
@@ -11,8 +11,10 @@ module DynamicMigrations
11
11
  module Columns
12
12
  def process_columns schema_name, table_name, configuration_columns, database_columns
13
13
  # process all the columns
14
+ log.info " Processing Columns..."
14
15
  column_names = (configuration_columns.keys + database_columns.keys).uniq
15
16
  column_names.each do |column_name|
17
+ log.info " Processing Column #{column_name}..."
16
18
  process_column schema_name, table_name, column_name, configuration_columns[column_name] || {}, database_columns[column_name] || {}
17
19
  end
18
20
  end
@@ -21,6 +23,8 @@ module DynamicMigrations
21
23
  # If the column exists in the configuration but not in the database
22
24
  # then we have to create it.
23
25
  if configuration_column[:exists] == true && !database_column[:exists]
26
+ log.info " Column `#{column_name}` exists in configuration but not in the database"
27
+
24
28
  # a migration to create the column
25
29
  column = @database.configured_schema(schema_name).table(table_name).column(column_name)
26
30
  @generator.add_column column
@@ -28,6 +32,8 @@ module DynamicMigrations
28
32
  # If the schema exists in the database but not in the configuration
29
33
  # then we need to delete it.
30
34
  elsif database_column[:exists] == true && !configuration_column[:exists]
35
+ log.info " Column `#{column_name}` exists in database but not in the configuration"
36
+
31
37
  # a migration to create the column
32
38
  column = @database.loaded_schema(schema_name).table(table_name).column(column_name)
33
39
  @generator.remove_column column
@@ -36,6 +42,9 @@ module DynamicMigrations
36
42
  # but the definition (except description, which is handled seeprately below) is different
37
43
  # then we need to update the definition.
38
44
  elsif configuration_column.except(:exists, :description).filter { |name, attributes| attributes[:matches] == false }.any?
45
+ log.info " Column `#{column_name}` exists in both configuration and the database"
46
+
47
+ log.info " Column `#{column_name}` is different"
39
48
  # update the column
40
49
  column = @database.configured_schema(schema_name).table(table_name).column(column_name)
41
50
  @generator.change_column column
@@ -43,8 +52,10 @@ module DynamicMigrations
43
52
  if configuration_column[:description][:matches] == false
44
53
  # if the description was removed
45
54
  if configuration_column[:description].nil?
55
+ log.info " Column `#{column_name}` description exists in database but not in the configuration"
46
56
  @generator.remove_column_comment column
47
57
  else
58
+ log.info " Column `#{column_name}` description does not match"
48
59
  @generator.set_column_comment column
49
60
  end
50
61
  end
@@ -52,11 +63,15 @@ module DynamicMigrations
52
63
  # If the column exists in both the configuration and database representations
53
64
  # but the description is different then we need to update the description.
54
65
  elsif configuration_column[:description][:matches] == false
66
+ log.info " Column `#{column_name}` exists in both configuration and the database"
67
+
55
68
  column = @database.configured_schema(schema_name).table(table_name).column(column_name)
56
69
  # if the description was removed
57
70
  if configuration_column[:description].nil?
71
+ log.info " Column `#{column_name}` description exists in database but not in the configuration"
58
72
  @generator.remove_column_comment column
59
73
  else
74
+ log.info " Column `#{column_name}` description does not match"
60
75
  @generator.set_column_comment column
61
76
  end
62
77
  end
@@ -11,8 +11,10 @@ module DynamicMigrations
11
11
  module ForeignKeyConstraints
12
12
  def process_foreign_key_constraints schema_name, table_name, configuration_foreign_key_constraints, database_foreign_key_constraints
13
13
  # process all the foreign_key_constraints
14
+ log.info " Processing Foreign Key Constraints..."
14
15
  foreign_key_constraint_names = (configuration_foreign_key_constraints.keys + database_foreign_key_constraints.keys).uniq
15
16
  foreign_key_constraint_names.each do |foreign_key_constraint_name|
17
+ log.info " Processing Foreign Key Constraint #{foreign_key_constraint_name}..."
16
18
  process_foreign_key_constraint schema_name, table_name, foreign_key_constraint_name, configuration_foreign_key_constraints[foreign_key_constraint_name] || {}, database_foreign_key_constraints[foreign_key_constraint_name] || {}
17
19
  end
18
20
  end
@@ -21,6 +23,8 @@ module DynamicMigrations
21
23
  # If the foreign_key_constraint exists in the configuration but not in the database
22
24
  # then we have to create it.
23
25
  if configuration_foreign_key_constraint[:exists] == true && !database_foreign_key_constraint[:exists]
26
+ log.info " Foreign Key Constraint `#{foreign_key_constraint_name}` exists in configuration but not in the database"
27
+
24
28
  # a migration to create the foreign_key_constraint
25
29
  foreign_key_constraint = @database.configured_schema(schema_name).table(table_name).foreign_key_constraint(foreign_key_constraint_name)
26
30
  @generator.add_foreign_key_constraint foreign_key_constraint
@@ -28,6 +32,8 @@ module DynamicMigrations
28
32
  # If the schema exists in the database but not in the configuration
29
33
  # then we need to delete it.
30
34
  elsif database_foreign_key_constraint[:exists] == true && !configuration_foreign_key_constraint[:exists]
35
+ log.info " Foreign Key Constraint `#{foreign_key_constraint_name}` exists in database but not in the configuration"
36
+
31
37
  # a migration to create the foreign_key_constraint
32
38
  foreign_key_constraint = @database.loaded_schema(schema_name).table(table_name).foreign_key_constraint(foreign_key_constraint_name)
33
39
  @generator.remove_foreign_key_constraint foreign_key_constraint
@@ -36,6 +42,9 @@ module DynamicMigrations
36
42
  # but the definition (except description, which is handled seeprately below) is different
37
43
  # then we need to update the definition.
38
44
  elsif configuration_foreign_key_constraint.except(:exists, :description).filter { |name, attributes| attributes[:matches] == false }.any?
45
+ log.info " Foreign Key Constraint `#{foreign_key_constraint_name}` exists in both configuration and the database"
46
+
47
+ log.info " Foreign Key Constraint `#{foreign_key_constraint_name}` is different"
39
48
  # recreate the foreign_key_constraint
40
49
  original_foreign_key_constraint = @database.loaded_schema(schema_name).table(table_name).foreign_key_constraint(foreign_key_constraint_name)
41
50
  updated_foreign_key_constraint = @database.configured_schema(schema_name).table(table_name).foreign_key_constraint(foreign_key_constraint_name)
@@ -44,8 +53,10 @@ module DynamicMigrations
44
53
  if configuration_foreign_key_constraint[:description][:matches] == false
45
54
  # if the description was removed
46
55
  if configuration_foreign_key_constraint[:description].nil?
56
+ log.info " Foreign Key Constraint `#{foreign_key_constraint_name}` description exists in database but not in the configuration"
47
57
  @generator.remove_foreign_key_constraint_comment updated_foreign_key_constraint
48
58
  else
59
+ log.info " Foreign Key Constraint `#{foreign_key_constraint_name}` does not match"
49
60
  @generator.set_foreign_key_constraint_comment updated_foreign_key_constraint
50
61
  end
51
62
  end
@@ -53,11 +64,15 @@ module DynamicMigrations
53
64
  # If the foreign_key_constraint exists in both the configuration and database representations
54
65
  # but the description is different then we need to update the description.
55
66
  elsif configuration_foreign_key_constraint[:description][:matches] == false
67
+ log.info " Foreign Key Constraint `#{foreign_key_constraint_name}` exists in both configuration and the database"
68
+
56
69
  foreign_key_constraint = @database.configured_schema(schema_name).table(table_name).foreign_key_constraint(foreign_key_constraint_name)
57
70
  # if the description was removed
58
71
  if configuration_foreign_key_constraint[:description].nil?
72
+ log.info " Foreign Key Constraint `#{foreign_key_constraint_name}` description exists in database but not in the configuration"
59
73
  @generator.remove_foreign_key_constraint_comment foreign_key_constraint
60
74
  else
75
+ log.info " Foreign Key Constraint `#{foreign_key_constraint_name}` description does not match"
61
76
  @generator.set_foreign_key_constraint_comment foreign_key_constraint
62
77
  end
63
78
  end
@@ -11,8 +11,10 @@ module DynamicMigrations
11
11
  module Indexes
12
12
  def process_indexes schema_name, table_name, configuration_indexes, database_indexes
13
13
  # process all the indexes
14
+ log.info " Processing Indexes..."
14
15
  index_names = (configuration_indexes.keys + database_indexes.keys).uniq
15
16
  index_names.each do |index_name|
17
+ log.info " Processing Index #{index_name}..."
16
18
  process_index schema_name, table_name, index_name, configuration_indexes[index_name] || {}, database_indexes[index_name] || {}
17
19
  end
18
20
  end
@@ -21,6 +23,8 @@ module DynamicMigrations
21
23
  # If the index exists in the configuration but not in the database
22
24
  # then we have to create it.
23
25
  if configuration_index[:exists] == true && !database_index[:exists]
26
+ log.info " Index `#{index_name}` exists in configuration but not in the database"
27
+
24
28
  # a migration to create the index
25
29
  index = @database.configured_schema(schema_name).table(table_name).index(index_name)
26
30
  @generator.add_index index
@@ -28,6 +32,8 @@ module DynamicMigrations
28
32
  # If the schema exists in the database but not in the configuration
29
33
  # then we need to delete it.
30
34
  elsif database_index[:exists] == true && !configuration_index[:exists]
35
+ log.info " Index `#{index_name}` exists in database but not in the configuration"
36
+
31
37
  # a migration to create the index
32
38
  index = @database.loaded_schema(schema_name).table(table_name).index(index_name)
33
39
  @generator.remove_index index
@@ -36,6 +42,9 @@ module DynamicMigrations
36
42
  # but the definition (except description, which is handled seeprately below) is different
37
43
  # then we need to update the definition.
38
44
  elsif configuration_index.except(:exists, :description).filter { |name, attributes| attributes[:matches] == false }.any?
45
+ log.info " Index `#{index_name}` exists in both configuration and the database"
46
+
47
+ log.info " Index `#{index_name}` is different"
39
48
  # rebild the index
40
49
  original_index = @database.loaded_schema(schema_name).table(table_name).index(index_name)
41
50
  updated_index = @database.configured_schema(schema_name).table(table_name).index(index_name)
@@ -44,8 +53,10 @@ module DynamicMigrations
44
53
  if configuration_index[:description][:matches] == false
45
54
  # if the description was removed
46
55
  if configuration_index[:description].nil?
56
+ log.info " Index `#{index_name}` description exists in database but not in the configuration"
47
57
  @generator.remove_index_comment updated_index
48
58
  else
59
+ log.info " Index `#{index_name}` does not match"
49
60
  @generator.set_index_comment updated_index
50
61
  end
51
62
  end
@@ -53,11 +64,15 @@ module DynamicMigrations
53
64
  # If the index exists in both the configuration and database representations
54
65
  # but the description is different then we need to update the description.
55
66
  elsif configuration_index[:description][:matches] == false
67
+ log.info " Index `#{index_name}` exists in both configuration and the database"
68
+
56
69
  index = @database.configured_schema(schema_name).table(table_name).index(index_name)
57
70
  # if the description was removed
58
71
  if configuration_index[:description].nil?
72
+ log.info " Index `#{index_name}` description exists in database but not in the configuration"
59
73
  @generator.remove_index_comment index
60
74
  else
75
+ log.info " Index `#{index_name}` description does not match"
61
76
  @generator.set_index_comment index
62
77
  end
63
78
  end
@@ -10,12 +10,15 @@ module DynamicMigrations
10
10
  module Tables
11
11
  module PrimaryKey
12
12
  def process_primary_key schema_name, table_name, configuration_primary_key, database_primary_key
13
+ log.info " Processing Primary Key..."
13
14
  configuration_primary_key_exists = configuration_primary_key && configuration_primary_key[:exists]
14
15
  database_primary_key_exists = database_primary_key && database_primary_key[:exists]
15
16
 
16
17
  # If the primary_key exists in the configuration but not in the database
17
18
  # then we have to create it.
18
19
  if configuration_primary_key_exists == true && database_primary_key_exists == false
20
+ log.info " Primary Key exists in configuration but not in the database"
21
+
19
22
  # a migration to create the primary_key
20
23
  primary_key = @database.configured_schema(schema_name).table(table_name).primary_key
21
24
  @generator.add_primary_key primary_key
@@ -23,19 +26,26 @@ module DynamicMigrations
23
26
  # If the schema exists in the database but not in the configuration
24
27
  # then we need to delete it.
25
28
  elsif configuration_primary_key_exists == false && database_primary_key_exists == true
29
+ log.info " Primary Key exists in database but not in the configuration"
30
+
26
31
  # a migration to create the primary_key
27
32
  primary_key = @database.loaded_schema(schema_name).table(table_name).primary_key
28
33
  @generator.remove_primary_key primary_key
29
34
 
30
35
  # If the primary_key exists in both the configuration and database representations
31
36
  elsif configuration_primary_key_exists == true && database_primary_key_exists == true
37
+ log.info " Primary Key exists in both configuration and the database"
38
+
32
39
  # If the definition (i.e. the column names) is different then we need to update the primary key.
33
40
  if configuration_primary_key.except(:exists, :description).filter { |name, attributes| attributes[:matches] == false }.any?
41
+ log.info " Primary Key is different"
34
42
  # recreate the primary_key
35
43
  original_primary_key = @database.loaded_schema(schema_name).table(table_name).primary_key
36
44
  updated_primary_key = @database.configured_schema(schema_name).table(table_name).primary_key
37
45
  @generator.recreate_primary_key original_primary_key, updated_primary_key
38
46
  end
47
+ else
48
+ log.info " Primary Key does not exist in either configuration or database"
39
49
  end
40
50
  end
41
51
  end
@@ -10,9 +10,11 @@ module DynamicMigrations
10
10
  module Tables
11
11
  module Triggers
12
12
  def process_triggers schema_name, table_name, configuration_triggers, database_triggers
13
+ log.info " Processing Triggers..."
13
14
  # process all the triggers
14
15
  trigger_names = (configuration_triggers.keys + database_triggers.keys).uniq
15
16
  trigger_names.each do |trigger_name|
17
+ log.info " Processing Trigger #{trigger_name}..."
16
18
  process_trigger schema_name, table_name, trigger_name, configuration_triggers[trigger_name] || {}, database_triggers[trigger_name] || {}
17
19
  end
18
20
  end
@@ -21,6 +23,8 @@ module DynamicMigrations
21
23
  # If the trigger exists in the configuration but not in the database
22
24
  # then we have to create it.
23
25
  if configuration_trigger[:exists] == true && !database_trigger[:exists]
26
+ log.info " Trigger `#{trigger_name}` exists in configuration but not in the database"
27
+
24
28
  # a migration to create the trigger
25
29
  trigger = @database.configured_schema(schema_name).table(table_name).trigger(trigger_name)
26
30
  @generator.add_trigger trigger
@@ -28,6 +32,8 @@ module DynamicMigrations
28
32
  # If the schema exists in the database but not in the configuration
29
33
  # then we need to delete it.
30
34
  elsif database_trigger[:exists] == true && !configuration_trigger[:exists]
35
+ log.info " Trigger `#{trigger_name}` exists in database but not in the configuration"
36
+
31
37
  # a migration to create the trigger
32
38
  trigger = @database.loaded_schema(schema_name).table(table_name).trigger(trigger_name)
33
39
  @generator.remove_trigger trigger
@@ -36,6 +42,9 @@ module DynamicMigrations
36
42
  # but the definition (except description, which is handled seeprately below) is different
37
43
  # then we need to update the definition.
38
44
  elsif configuration_trigger.except(:exists, :description).filter { |name, attributes| attributes[:matches] == false }.any?
45
+ log.info " Trigger `#{trigger_name}` exists in both configuration and the database"
46
+
47
+ log.info " Trigger `#{trigger_name}` is different"
39
48
  # recreate the trigger
40
49
  original_trigger = @database.loaded_schema(schema_name).table(table_name).trigger(trigger_name)
41
50
  updated_trigger = @database.configured_schema(schema_name).table(table_name).trigger(trigger_name)
@@ -44,8 +53,10 @@ module DynamicMigrations
44
53
  if configuration_trigger[:description][:matches] == false
45
54
  # if the description was removed
46
55
  if configuration_trigger[:description].nil?
56
+ log.info " Trigger `#{trigger_name}` description exists in database but not in the configuration"
47
57
  @generator.remove_trigger_comment updated_trigger
48
58
  else
59
+ log.info " Trigger `#{trigger_name}` description does not match"
49
60
  @generator.set_trigger_comment updated_trigger
50
61
  end
51
62
  end
@@ -53,11 +64,15 @@ module DynamicMigrations
53
64
  # If the trigger exists in both the configuration and database representations
54
65
  # but the description is different then we need to update the description.
55
66
  elsif configuration_trigger[:description][:matches] == false
67
+ log.info " Trigger `#{trigger_name}` exists in both configuration and the database"
68
+
56
69
  trigger = @database.configured_schema(schema_name).table(table_name).trigger(trigger_name)
57
70
  # if the description was removed
58
71
  if configuration_trigger[:description].nil?
72
+ log.info " Trigger `#{trigger_name}` description exists in database but not in the configuration"
59
73
  @generator.remove_trigger_comment trigger
60
74
  else
75
+ log.info " Trigger `#{trigger_name}` description does not match"
61
76
  @generator.set_trigger_comment trigger
62
77
  end
63
78
  end
@@ -10,9 +10,11 @@ module DynamicMigrations
10
10
  module Tables
11
11
  module UniqueConstraints
12
12
  def process_unique_constraints schema_name, table_name, configuration_unique_constraints, database_unique_constraints
13
+ log.info " Processing Unique Constraints..."
13
14
  # process all the unique_constraints
14
15
  unique_constraint_names = (configuration_unique_constraints.keys + database_unique_constraints.keys).uniq
15
16
  unique_constraint_names.each do |unique_constraint_name|
17
+ log.info " Processing Unique Constraint #{unique_constraint_name}..."
16
18
  process_unique_constraint schema_name, table_name, unique_constraint_name, configuration_unique_constraints[unique_constraint_name] || {}, database_unique_constraints[unique_constraint_name] || {}
17
19
  end
18
20
  end
@@ -21,6 +23,8 @@ module DynamicMigrations
21
23
  # If the unique_constraint exists in the configuration but not in the database
22
24
  # then we have to create it.
23
25
  if configuration_unique_constraint[:exists] == true && !database_unique_constraint[:exists]
26
+ log.info " Unique Constraint `#{unique_constraint_name}` exists in configuration but not in the database"
27
+
24
28
  # a migration to create the unique_constraint
25
29
  unique_constraint = @database.configured_schema(schema_name).table(table_name).unique_constraint(unique_constraint_name)
26
30
  @generator.add_unique_constraint unique_constraint
@@ -28,6 +32,8 @@ module DynamicMigrations
28
32
  # If the schema exists in the database but not in the configuration
29
33
  # then we need to delete it.
30
34
  elsif database_unique_constraint[:exists] == true && !configuration_unique_constraint[:exists]
35
+ log.info " Unique Constraint `#{unique_constraint_name}` exists in database but not in the configuration"
36
+
31
37
  # a migration to create the unique_constraint
32
38
  unique_constraint = @database.loaded_schema(schema_name).table(table_name).unique_constraint(unique_constraint_name)
33
39
  @generator.remove_unique_constraint unique_constraint
@@ -36,6 +42,9 @@ module DynamicMigrations
36
42
  # but the definition (except description, which is handled seeprately below) is different
37
43
  # then we need to update the definition.
38
44
  elsif configuration_unique_constraint.except(:exists, :description).filter { |name, attributes| attributes[:matches] == false }.any?
45
+ log.info " Unique Constraint `#{unique_constraint_name}` exists in both configuration and the database"
46
+
47
+ log.info " Unique Constraint `#{unique_constraint_name}` is different"
39
48
  # recreate the unique_constraint
40
49
  original_unique_constraint = @database.loaded_schema(schema_name).table(table_name).unique_constraint(unique_constraint_name)
41
50
  updated_unique_constraint = @database.configured_schema(schema_name).table(table_name).unique_constraint(unique_constraint_name)
@@ -44,8 +53,10 @@ module DynamicMigrations
44
53
  if configuration_unique_constraint[:description][:matches] == false
45
54
  # if the description was removed
46
55
  if configuration_unique_constraint[:description].nil?
56
+ log.info " Unique Constraint `#{unique_constraint_name}` description exists in database but not in the configuration"
47
57
  @generator.remove_unique_constraint_comment updated_unique_constraint
48
58
  else
59
+ log.info " Unique Constraint `#{unique_constraint_name}` description does not match"
49
60
  @generator.set_unique_constraint_comment updated_unique_constraint
50
61
  end
51
62
  end
@@ -53,11 +64,15 @@ module DynamicMigrations
53
64
  # If the unique_constraint exists in both the configuration and database representations
54
65
  # but the description is different then we need to update the description.
55
66
  elsif configuration_unique_constraint[:description][:matches] == false
67
+ log.info " Unique Constraint `#{unique_constraint_name}` exists in both configuration and the database"
68
+
56
69
  unique_constraint = @database.configured_schema(schema_name).table(table_name).unique_constraint(unique_constraint_name)
57
70
  # if the description was removed
58
71
  if configuration_unique_constraint[:description].nil?
72
+ log.info " Unique Constraint `#{unique_constraint_name}` description exists in database but not in the configuration"
59
73
  @generator.remove_unique_constraint_comment unique_constraint
60
74
  else
75
+ log.info " Unique Constraint `#{unique_constraint_name}` description does not match"
61
76
  @generator.set_unique_constraint_comment unique_constraint
62
77
  end
63
78
  end
@@ -11,8 +11,10 @@ module DynamicMigrations
11
11
  module Validations
12
12
  def process_validations schema_name, table_name, configuration_validations, database_validations
13
13
  # process all the validations
14
+ log.info " Processing Validations..."
14
15
  validation_names = (configuration_validations.keys + database_validations.keys).uniq
15
16
  validation_names.each do |validation_name|
17
+ log.info " Processing Validation #{validation_name}..."
16
18
  process_validation schema_name, table_name, validation_name, configuration_validations[validation_name] || {}, database_validations[validation_name] || {}
17
19
  end
18
20
  end
@@ -21,6 +23,8 @@ module DynamicMigrations
21
23
  # If the validation exists in the configuration but not in the database
22
24
  # then we have to create it.
23
25
  if configuration_validation[:exists] == true && !database_validation[:exists]
26
+ log.info " Validation `#{validation_name}` exists in configuration but not in the database"
27
+
24
28
  # a migration to create the validation
25
29
  validation = @database.configured_schema(schema_name).table(table_name).validation(validation_name)
26
30
  @generator.add_validation validation
@@ -28,6 +32,8 @@ module DynamicMigrations
28
32
  # If the schema exists in the database but not in the configuration
29
33
  # then we need to delete it.
30
34
  elsif database_validation[:exists] == true && !configuration_validation[:exists]
35
+ log.info " Validation `#{validation_name}` exists in database but not in the configuration"
36
+
31
37
  # a migration to create the validation
32
38
  validation = @database.loaded_schema(schema_name).table(table_name).validation(validation_name)
33
39
  @generator.remove_validation validation
@@ -36,6 +42,9 @@ module DynamicMigrations
36
42
  # but the definition (except description, which is handled seeprately below) is different
37
43
  # then we need to update the definition.
38
44
  elsif configuration_validation.except(:exists, :description).filter { |name, attributes| attributes[:matches] == false }.any?
45
+ log.info " Validation `#{validation_name}` exists in both configuration and the database"
46
+
47
+ log.info " Validation `#{validation_name}` is different"
39
48
  # recreate the validation
40
49
  original_validation = @database.loaded_schema(schema_name).table(table_name).validation(validation_name)
41
50
  updated_validation = @database.configured_schema(schema_name).table(table_name).validation(validation_name)
@@ -44,8 +53,10 @@ module DynamicMigrations
44
53
  if configuration_validation[:description][:matches] == false
45
54
  # if the description was removed
46
55
  if configuration_validation[:description].nil?
56
+ log.info " Validation `#{validation_name}` description exists in database but not in the configuration"
47
57
  @generator.remove_validation_comment updated_validation
48
58
  else
59
+ log.info " Validation `#{validation_name}` does not match"
49
60
  @generator.set_validation_comment updated_validation
50
61
  end
51
62
  end
@@ -53,11 +64,15 @@ module DynamicMigrations
53
64
  # If the validation exists in both the configuration and database representations
54
65
  # but the description is different then we need to update the description.
55
66
  elsif configuration_validation[:description][:matches] == false
67
+ log.info " Validation `#{validation_name}` exists in both configuration and the database"
68
+
56
69
  validation = @database.configured_schema(schema_name).table(table_name).validation(validation_name)
57
70
  # if the description was removed
58
71
  if configuration_validation[:description].nil?
72
+ log.info " Validation `#{validation_name}` description exists in database but not in the configuration"
59
73
  @generator.remove_validation_comment validation
60
74
  else
75
+ log.info " Validation `#{validation_name}` does not match"
61
76
  @generator.set_validation_comment validation
62
77
  end
63
78
  end
@@ -10,8 +10,10 @@ module DynamicMigrations
10
10
  module Tables
11
11
  def process_tables schema_name, configuration_tables, database_tables
12
12
  # process all the tables
13
+ log.info " Processing Tables..."
13
14
  table_names = (configuration_tables.keys + database_tables.keys).uniq
14
15
  table_names.each do |table_name|
16
+ log.info " Processing Table #{table_name}..."
15
17
  process_table schema_name, table_name, configuration_tables[table_name] || {}, database_tables[table_name] || {}
16
18
  end
17
19
  end
@@ -20,6 +22,8 @@ module DynamicMigrations
20
22
  # If the table exists in the configuration but not in the database
21
23
  # then we have to create it.
22
24
  if configuration_table[:exists] == true && !database_table[:exists]
25
+ log.info " Table `#{table_name}` exists in configuration but not in the database"
26
+
23
27
  # a migration to create the table
24
28
  table = @database.configured_schema(schema_name).table(table_name)
25
29
  @generator.create_table table
@@ -31,6 +35,8 @@ module DynamicMigrations
31
35
  # If the schema exists in the database but not in the configuration
32
36
  # then we need to delete it.
33
37
  elsif database_table[:exists] == true && !configuration_table[:exists]
38
+ log.info " Table `#{table_name}` exists in database but not in the configuration"
39
+
34
40
  # we process everything else before we drop the table, because the other
35
41
  # database objects are dependent on the table
36
42
  process_dependents schema_name, table_name, {}, database_table
@@ -42,11 +48,15 @@ module DynamicMigrations
42
48
  # If the table exists in both the configuration and database representations
43
49
  # but the description is different then we need to update the description.
44
50
  elsif configuration_table[:description][:matches] == false
51
+ log.info " Table `#{table_name}` exists in both configuration and the database"
52
+
45
53
  table = @database.configured_schema(schema_name).table(table_name)
46
54
  # if the description was removed
47
55
  if configuration_table[:description].nil?
56
+ log.info " Table `#{table_name}` description exists in database but not in the configuration"
48
57
  @generator.remove_table_comment table
49
58
  else
59
+ log.info " Table `#{table_name}` description does not match"
50
60
  @generator.set_table_comment table
51
61
  end
52
62
 
@@ -54,6 +64,7 @@ module DynamicMigrations
54
64
  process_dependents schema_name, table_name, configuration_table, database_table
55
65
 
56
66
  else
67
+ log.info " Table `#{table_name}` exists in both configuration and the database"
57
68
  # process everything else
58
69
  process_dependents schema_name, table_name, configuration_table, database_table
59
70
 
@@ -11,6 +11,8 @@ module DynamicMigrations
11
11
  # if the schema exists in the configuration but not in the database
12
12
  # then we have to create it
13
13
  if configuration_schema[:exists] == true && !database_schema[:exists]
14
+ log.info "Schema `#{schema_name}` exists in configuration but not in the database"
15
+
14
16
  # a migration to create the schema
15
17
  schema = @database.configured_schema schema_name
16
18
  @generator.create_schema schema
@@ -24,6 +26,7 @@ module DynamicMigrations
24
26
  # if the schema exists in the database but not in the configuration
25
27
  # then we need to delete it
26
28
  elsif database_schema[:exists] == true && !configuration_schema[:exists]
29
+ log.info "Schema `#{schema_name}` exists in database but not in the configuration"
27
30
  # we process the tables and functions before we drop the schema
28
31
  # as this will drop any dependencies on the schema
29
32
  process_functions schema_name, {}, database_schema[:functions]
@@ -37,6 +40,7 @@ module DynamicMigrations
37
40
  # if the schema exists in both the configuration and database representations
38
41
  # then we just need to process the tables and functions
39
42
  else
43
+ log.info "Schema `#{schema_name}` exists in both configuration and the database"
40
44
  process_functions schema_name, configuration_schema[:functions], database_schema[:functions]
41
45
  process_enums schema_name, configuration_schema[:enums], database_schema[:enums]
42
46
  process_tables schema_name, configuration_schema[:tables], database_schema[:tables]
@@ -26,6 +26,8 @@ module DynamicMigrations
26
26
  include Schemas::Tables::Validations
27
27
 
28
28
  def initialize database, differences
29
+ @logger = Logging.logger[self]
30
+
29
31
  raise UnexpectedDatabaseObjectError, database unless database.is_a? Database
30
32
  @database = database
31
33
 
@@ -38,15 +40,19 @@ module DynamicMigrations
38
40
 
39
41
  def migrations
40
42
  # process all the extensions
43
+ log.info "Processing Extensions..."
41
44
  extension_names = differences[:configuration][:extensions].keys
42
45
  extension_names.each do |extension_name|
46
+ log.info "Processing Extension `#{extension_name}`..."
43
47
  process_extension extension_name, differences[:configuration][:extensions][extension_name], differences[:database][:extensions][extension_name]
44
48
  end
45
49
 
46
50
  # process all the schemas (we can fetch the schema names from either the
47
51
  # configuration or the database object)
52
+ log.info "Processing Schemas..."
48
53
  schema_names = differences[:configuration][:schemas].keys
49
54
  schema_names.each do |schema_name|
55
+ log.info "Processing Schema `#{schema_name}`..."
50
56
  process_schema schema_name, differences[:configuration][:schemas][schema_name], differences[:database][:schemas][schema_name]
51
57
  end
52
58
 
@@ -59,6 +65,10 @@ module DynamicMigrations
59
65
  def differences
60
66
  @differences_hash ||= @differences.to_h
61
67
  end
68
+
69
+ def log
70
+ @logger
71
+ end
62
72
  end
63
73
  end
64
74
  end
@@ -18,6 +18,8 @@ module DynamicMigrations
18
18
  end
19
19
 
20
20
  def initialize database
21
+ @logger = Logging.logger[self]
22
+
21
23
  raise ExpectedDatabaseError, database unless database.is_a? Database
22
24
  @database = database
23
25
  end
@@ -31,19 +33,28 @@ module DynamicMigrations
31
33
  # return a hash representing any differenced betweek the loaded and configured
32
34
  # versions of the current database
33
35
  def to_h
34
- {
35
- configuration: {
36
- schemas: self.class.compare_schemas(@database.configured_schemas_hash, @database.loaded_schemas_hash),
37
- extensions: self.class.compare_extensions(@database.configured_extensions, @database.loaded_extensions)
38
- },
39
- database: {
40
- schemas: self.class.compare_schemas(@database.loaded_schemas_hash, @database.configured_schemas_hash),
41
- extensions: self.class.compare_extensions(@database.loaded_extensions, @database.configured_extensions)
42
- }
36
+ log.info "Building differences between configured and loaded database structure..."
37
+
38
+ # build progressively, so we can add logging around the two different opperations
39
+ results = {}
40
+
41
+ log.info "Comparing configured database structure to loaded database structure..."
42
+ results[:configuration] = {
43
+ schemas: self.class.compare_schemas(@database.configured_schemas_hash, @database.loaded_schemas_hash),
44
+ extensions: self.class.compare_extensions(@database.configured_extensions, @database.loaded_extensions)
45
+ }
46
+
47
+ log.info "Comparing loaded database structure to configured database structure..."
48
+ results[:database] = {
49
+ schemas: self.class.compare_schemas(@database.loaded_schemas_hash, @database.configured_schemas_hash),
50
+ extensions: self.class.compare_extensions(@database.loaded_extensions, @database.configured_extensions)
43
51
  }
52
+ results
44
53
  end
45
54
 
46
55
  def self.compare_extensions extensions, comparison_extensions
56
+ log.info "Comparing Extensions..."
57
+
47
58
  result = {}
48
59
  # the extensions
49
60
  extensions.each do |extension_name|
@@ -65,6 +76,8 @@ module DynamicMigrations
65
76
  end
66
77
 
67
78
  def self.compare_schemas schemas, comparison_schemas
79
+ log.info "Comparing Schemas..."
80
+
68
81
  result = {}
69
82
  # the base schemas
70
83
  schemas.each do |schema_name, schema|
@@ -88,6 +101,8 @@ module DynamicMigrations
88
101
  def self.compare_schema schema, comparison_schema
89
102
  raise SchemaRequiredError if schema.nil?
90
103
 
104
+ log.info "Comparing Schema `#{schema.name}`"
105
+
91
106
  comparison_tables = comparison_schema.nil? ? {} : comparison_schema.tables_hash
92
107
  comparison_functions = comparison_schema.nil? ? {} : comparison_schema.functions_hash
93
108
  comparison_enums = comparison_schema.nil? ? {} : comparison_schema.enums_hash
@@ -103,6 +118,8 @@ module DynamicMigrations
103
118
  # an object which represents the provided `tables` and any differences
104
119
  # between it and the `comparison_tables`
105
120
  def self.compare_tables tables, comparison_tables
121
+ log.info "Comparing Tables..."
122
+
106
123
  result = {}
107
124
  # the base tables
108
125
  tables.each do |table_name, table|
@@ -126,6 +143,8 @@ module DynamicMigrations
126
143
  def self.compare_table table, comparison_table
127
144
  raise TableRequiredError if table.nil?
128
145
 
146
+ log.info "Comparing Table `#{table.name}`"
147
+
129
148
  primary_key = table.has_primary_key? ? table.primary_key : nil
130
149
  if comparison_table
131
150
  comparison_primary_key = comparison_table.has_primary_key? ? comparison_table.primary_key : nil
@@ -168,6 +187,8 @@ module DynamicMigrations
168
187
  # an object which represents the provided `functions` and any differences
169
188
  # between it and the `comparison_functions`
170
189
  def self.compare_functions functions, comparison_functions
190
+ log.info "Comparing Functions..."
191
+
171
192
  result = {}
172
193
  # the base functions
173
194
  functions.each do |function_name, function|
@@ -191,6 +212,8 @@ module DynamicMigrations
191
212
  # an object which represents the provided `enums` and any differences
192
213
  # between it and the `comparison_enums`
193
214
  def self.compare_enums enums, comparison_enums
215
+ log.info "Comparing Enums..."
216
+
194
217
  result = {}
195
218
  # the base enums
196
219
  enums.each do |enum_name, enum|
@@ -214,6 +237,8 @@ module DynamicMigrations
214
237
  # an object which represents the provided `columns` and any differences
215
238
  # between it and the `comparison_columns`
216
239
  def self.compare_columns columns, comparison_columns
240
+ log.info "Comparing Columns..."
241
+
217
242
  result = {}
218
243
  # the base columns
219
244
  columns.each do |column_name, column|
@@ -241,6 +266,8 @@ module DynamicMigrations
241
266
  # an object which represents the provided `triggers` and any differences
242
267
  # between it and the `comparison_triggers`
243
268
  def self.compare_triggers triggers, comparison_triggers
269
+ log.info "Comparing Triggers..."
270
+
244
271
  result = {}
245
272
  # the base triggers
246
273
  triggers.each do |trigger_name, trigger|
@@ -272,6 +299,8 @@ module DynamicMigrations
272
299
  # an object which represents the provided `unique_constraints` and any differences
273
300
  # between it and the `comparison_unique_constraints`
274
301
  def self.compare_unique_constraints unique_constraints, comparison_unique_constraints
302
+ log.info "Comparing Unique Constraints..."
303
+
275
304
  result = {}
276
305
  # the base unique_constraints
277
306
  unique_constraints.each do |name, unique_constraint|
@@ -298,6 +327,8 @@ module DynamicMigrations
298
327
  # an object which represents the provided `indexes` and any differences
299
328
  # between it and the `comparison_indexes`
300
329
  def self.compare_indexes indexes, comparison_indexes
330
+ log.info "Comparing Indexes..."
331
+
301
332
  result = {}
302
333
  # the base indexes
303
334
  indexes.each do |name, index|
@@ -327,6 +358,8 @@ module DynamicMigrations
327
358
  # an object which represents the provided `validations` and any differences
328
359
  # between it and the `comparison_validations`
329
360
  def self.compare_validations validations, comparison_validations
361
+ log.info "Comparing Validations..."
362
+
330
363
  result = {}
331
364
  # the base validations
332
365
  validations.each do |name, validation|
@@ -354,6 +387,8 @@ module DynamicMigrations
354
387
  # an object which represents the provided `foreign_key_constraints` and any differences
355
388
  # between it and the `comparison_foreign_key_constraints`
356
389
  def self.compare_foreign_key_constraints foreign_key_constraints, comparison_foreign_key_constraints
390
+ log.info "Comparing Foreign Key Constraints..."
391
+
357
392
  result = {}
358
393
  # the base foreign_key_constraints
359
394
  foreign_key_constraints.each do |name, foreign_key_constraint|
@@ -391,8 +426,14 @@ module DynamicMigrations
391
426
  exists: false
392
427
  }
393
428
  else
429
+ type = base.class.name.split("::").last
430
+ name = base.is_a?(Schema::Table::PrimaryKey) ? nil : base.name
431
+ log.info " Comparing #{type} `#{name}`"
432
+
394
433
  result = {}
395
434
  method_list.each do |method_name|
435
+ log.info " Comparing `#{method_name}`"
436
+
396
437
  matches = (comparison && comparison.send(method_name) == base.send(method_name)) || false
397
438
  result[method_name] = {
398
439
  value: base.send(method_name),
@@ -403,6 +444,14 @@ module DynamicMigrations
403
444
  result
404
445
  end
405
446
  end
447
+
448
+ def self.log
449
+ @logger ||= Logging.logger[self]
450
+ end
451
+
452
+ def log
453
+ @logger
454
+ end
406
455
  end
407
456
  end
408
457
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamicMigrations
4
- VERSION = "3.8.2"
4
+ VERSION = "3.8.3"
5
5
  end
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # postgres gem
3
4
  require "pg"
5
+ # logging gem
6
+ require "logging"
4
7
 
5
8
  require "dynamic_migrations/version"
6
9
  require "dynamic_migrations/invalid_source_error"
@@ -10,6 +10,9 @@ module DynamicMigrations
10
10
  module Extensions
11
11
 
12
12
  private
13
+ # this method is available on the ToMigrations class which includes this module
14
+ def log: -> Logging::Logger
15
+
13
16
  def process_extension: (Symbol extension_name, untyped configuration_extension, untyped database_extension) -> void
14
17
 
15
18
 
@@ -13,6 +13,8 @@ module DynamicMigrations
13
13
  private
14
14
  def process_enums: (Symbol schema_name, untyped configuration_enums, untyped database_enums) -> void
15
15
  def process_enum: (Symbol schema_name, Symbol enum_name, untyped configuration_enum, untyped database_enum) -> void
16
+ # this method is available on the ToMigrations class which includes this module
17
+ def log: -> Logging::Logger
16
18
 
17
19
  end
18
20
  end
@@ -13,6 +13,8 @@ module DynamicMigrations
13
13
  private
14
14
  def process_functions: (Symbol schema_name, untyped configuration_functions, untyped database_functions) -> void
15
15
  def process_function: (Symbol schema_name, Symbol function_name, untyped configuration_function, untyped database_function) -> void
16
+ # this method is available on the ToMigrations class which includes this module
17
+ def log: -> Logging::Logger
16
18
 
17
19
  end
18
20
  end
@@ -14,6 +14,8 @@ module DynamicMigrations
14
14
  private
15
15
  def process_columns: (Symbol schema_name, Symbol table_name, untyped configuration_columns, untyped database_columns) -> void
16
16
  def process_column: (Symbol schema_name, Symbol table_name, Symbol column_name, untyped configuration_column, untyped database_column) -> void
17
+ # this method is available on the ToMigrations class which includes this module
18
+ def log: -> Logging::Logger
17
19
 
18
20
  end
19
21
  end
@@ -14,6 +14,8 @@ module DynamicMigrations
14
14
  private
15
15
  def process_foreign_key_constraints: (Symbol schema_name, Symbol table_name, untyped configuration_foreign_key_constraints, untyped database_foreign_key_constraints) -> void
16
16
  def process_foreign_key_constraint: (Symbol schema_name, Symbol table_name, Symbol foreign_key_constraint_name, untyped configuration_foreign_key_constraint, untyped database_foreign_key_constraint) -> void
17
+ # this method is available on the ToMigrations class which includes this module
18
+ def log: -> Logging::Logger
17
19
 
18
20
  end
19
21
  end
@@ -14,6 +14,8 @@ module DynamicMigrations
14
14
  private
15
15
  def process_indexes: (Symbol schema_name, Symbol table_name, untyped configuration_indexes, untyped database_indexes) -> void
16
16
  def process_index: (Symbol schema_name, Symbol table_name, Symbol index_name, untyped configuration_index, untyped database_index) -> void
17
+ # this method is available on the ToMigrations class which includes this module
18
+ def log: -> Logging::Logger
17
19
 
18
20
  end
19
21
  end
@@ -13,6 +13,8 @@ module DynamicMigrations
13
13
 
14
14
  private
15
15
  def process_primary_key: (Symbol schema_name, Symbol table_name, untyped configuration_primary_key, untyped database_primary_key) -> void
16
+ # this method is available on the ToMigrations class which includes this module
17
+ def log: -> Logging::Logger
16
18
 
17
19
  end
18
20
  end
@@ -14,6 +14,8 @@ module DynamicMigrations
14
14
  private
15
15
  def process_triggers: (Symbol schema_name, Symbol table_name, untyped configuration_triggers, untyped database_triggers) -> void
16
16
  def process_trigger: (Symbol schema_name, Symbol table_name, Symbol trigger_name, untyped configuration_trigger, untyped database_trigger) -> void
17
+ # this method is available on the ToMigrations class which includes this module
18
+ def log: -> Logging::Logger
17
19
 
18
20
  end
19
21
  end
@@ -14,6 +14,8 @@ module DynamicMigrations
14
14
  private
15
15
  def process_unique_constraints: (Symbol schema_name, Symbol table_name, untyped configuration_unique_constraints, untyped database_unique_constraints) -> void
16
16
  def process_unique_constraint: (Symbol schema_name, Symbol table_name, Symbol unique_constraint_name, untyped configuration_unique_constraint, untyped database_unique_constraint) -> void
17
+ # this method is available on the ToMigrations class which includes this module
18
+ def log: -> Logging::Logger
17
19
 
18
20
  end
19
21
  end
@@ -14,6 +14,8 @@ module DynamicMigrations
14
14
  private
15
15
  def process_validations: (Symbol schema_name, Symbol table_name, untyped configuration_validations, untyped database_validations) -> void
16
16
  def process_validation: (Symbol schema_name, Symbol table_name, Symbol validation_name, untyped configuration_validation, untyped database_validation) -> void
17
+ # this method is available on the ToMigrations class which includes this module
18
+ def log: -> Logging::Logger
17
19
 
18
20
  end
19
21
  end
@@ -22,6 +22,8 @@ module DynamicMigrations
22
22
  def process_triggers: (Symbol schema_name, Symbol table_name, untyped configuration_triggers, untyped database_triggers) -> void
23
23
  def process_unique_constraints: (Symbol schema_name, Symbol table_name, untyped configuration_unique_constraints, untyped database_unique_constraints) -> void
24
24
  def process_validations: (Symbol schema_name, Symbol table_name, untyped configuration_validations, untyped database_validations) -> void
25
+ # this method is available on the ToMigrations class which includes this module
26
+ def log: -> Logging::Logger
25
27
 
26
28
  end
27
29
  end
@@ -21,6 +21,9 @@ module DynamicMigrations
21
21
  # this method comes from the Tables module
22
22
  def process_tables: (Symbol schema_name, untyped configuration_tables, untyped database_tables) -> void
23
23
 
24
+ # this method is available on the ToMigrations class which includes this module
25
+ def log: -> Logging::Logger
26
+
24
27
  end
25
28
  end
26
29
  end
@@ -8,6 +8,7 @@ module DynamicMigrations
8
8
  class Differences
9
9
  class ToMigrations
10
10
  @database: Database
11
+ @logger: Logging::Logger
11
12
  @differences_hash: untyped
12
13
  @generator: Generator
13
14
  @differences: Differences
@@ -30,6 +31,7 @@ module DynamicMigrations
30
31
 
31
32
  private
32
33
  def differences: -> Hash[untyped, untyped]
34
+ def log: -> Logging::Logger
33
35
 
34
36
  # this method comes from the Schemas module
35
37
  def process_schema: (Symbol schema_name, untyped configuration_schema, untyped database_schema) -> void
@@ -4,18 +4,11 @@ module DynamicMigrations
4
4
  class Database
5
5
  class Differences
6
6
  @database: Database
7
+ @logger: Logging::Logger
8
+ self.@logger: Logging::Logger
7
9
 
8
10
  def initialize: (Database database) -> void
9
- def to_h: -> {
10
- configuration: {
11
- schemas: Hash[Symbol, untyped],
12
- extensions: Hash[Symbol, {exists: bool}]
13
- },
14
- database: {
15
- schemas: Hash[Symbol, untyped],
16
- extensions: Hash[Symbol, {exists: bool}]
17
- }
18
- }
11
+ def to_h: -> untyped
19
12
  def to_migrations: -> Hash[Symbol, Array[{name: Symbol, content: String}]]
20
13
 
21
14
  def self.compare_schemas: (Hash[Symbol, Schema] schemas, Hash[Symbol, Schema] comparison_schemas) -> Hash[Symbol, untyped]
@@ -34,7 +27,11 @@ module DynamicMigrations
34
27
  def self.compare_indexes: (Hash[Symbol, Schema::Table::Index] indexes, Hash[Symbol, Schema::Table::Index] comparison_indexes) -> Hash[Symbol, untyped]
35
28
  def self.compare_validations: (Hash[Symbol, Schema::Table::Validation] validations, Hash[Symbol, Schema::Table::Validation] comparison_validations) -> Hash[Symbol, untyped]
36
29
  def self.compare_foreign_key_constraints: (Hash[Symbol, Schema::Table::ForeignKeyConstraint] foreign_key_constraints, Hash[Symbol, Schema::Table::ForeignKeyConstraint] comparison_foreign_key_constraints) -> Hash[Symbol, untyped]
37
- def self.compare_record: (Object | nil base, Object | nil comparison, Array[Symbol] method_list) -> Hash[Symbol, untyped]
30
+ def self.compare_record: (untyped | nil base, Object | nil comparison, Array[Symbol] method_list) -> Hash[Symbol, untyped]
31
+ def self.log: -> Logging::Logger
32
+
33
+ private
34
+ def log: -> Logging::Logger
38
35
 
39
36
  class ExpectedDatabaseError < StandardError
40
37
  end
data/sig/logging.rbs ADDED
@@ -0,0 +1,11 @@
1
+ module Logging
2
+ class Logger
3
+ def []: (Object) -> Logger
4
+
5
+ def debug: (String) -> void
6
+ def info: (String) -> void
7
+ def warn: (String) -> void
8
+ end
9
+
10
+ def self.logger: () -> Logger
11
+ end
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.8.2
4
+ version: 3.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Ulliott
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: logging
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: yaml
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -247,6 +261,7 @@ files:
247
261
  - sig/dynamic_migrations/postgres/server/database/structure_loader.rbs
248
262
  - sig/dynamic_migrations/postgres/server/database/triggers_and_functions_loader.rbs
249
263
  - sig/dynamic_migrations/postgres/server/database/validations_loader.rbs
264
+ - sig/logging.rbs
250
265
  - sig/pg.rbs
251
266
  - sig/tsort.rbs
252
267
  homepage: