dynamic_migrations 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/dynamic_migrations/postgres/generator/column.rb +44 -19
- data/lib/dynamic_migrations/postgres/generator/foreign_key_constraint.rb +35 -14
- data/lib/dynamic_migrations/postgres/generator/fragment.rb +37 -2
- data/lib/dynamic_migrations/postgres/generator/function.rb +50 -25
- data/lib/dynamic_migrations/postgres/generator/index.rb +34 -14
- data/lib/dynamic_migrations/postgres/generator/migration.rb +175 -0
- data/lib/dynamic_migrations/postgres/generator/migration_dependency_sorter.rb +21 -0
- data/lib/dynamic_migrations/postgres/generator/primary_key.rb +16 -6
- data/lib/dynamic_migrations/postgres/generator/schema.rb +14 -6
- data/lib/dynamic_migrations/postgres/generator/schema_migration.rb +17 -0
- data/lib/dynamic_migrations/postgres/generator/table.rb +39 -19
- data/lib/dynamic_migrations/postgres/generator/table_migration.rb +51 -0
- data/lib/dynamic_migrations/postgres/generator/trigger.rb +34 -14
- data/lib/dynamic_migrations/postgres/generator/unique_constraint.rb +34 -14
- data/lib/dynamic_migrations/postgres/generator/validation.rb +38 -18
- data/lib/dynamic_migrations/postgres/generator.rb +163 -294
- data/lib/dynamic_migrations/postgres/server/database/connection.rb +15 -0
- data/lib/dynamic_migrations/version.rb +1 -1
- data/lib/dynamic_migrations.rb +4 -2
- metadata +6 -4
- data/lib/dynamic_migrations/postgres/generator/schema_migrations/section.rb +0 -37
- data/lib/dynamic_migrations/postgres/generator/schema_migrations.rb +0 -92
@@ -1,92 +0,0 @@
|
|
1
|
-
module DynamicMigrations
|
2
|
-
module Postgres
|
3
|
-
class Generator
|
4
|
-
class SchemaMigrations
|
5
|
-
class SectionNotFoundError < StandardError
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_reader :current_migration_sections
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@migrations = []
|
12
|
-
@current_migration_sections = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def add_fragment schema_name, table_name, content_type, fragment
|
16
|
-
@current_migration_sections << Section.new(schema_name, table_name, content_type, fragment)
|
17
|
-
end
|
18
|
-
|
19
|
-
def finalize
|
20
|
-
if @current_migration_sections.any?
|
21
|
-
|
22
|
-
contents = []
|
23
|
-
@current_migration_sections.each do |section|
|
24
|
-
contents << section.to_s
|
25
|
-
# add an empty line between sections (unless this is a comment section)
|
26
|
-
unless section.is_comment?
|
27
|
-
contents << ""
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
@migrations << {
|
32
|
-
name: generate_current_migration_name,
|
33
|
-
content: contents.join("\n").strip
|
34
|
-
}
|
35
|
-
|
36
|
-
@current_migration_sections = []
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def to_a
|
41
|
-
@migrations
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def current_migration_has_content_type? content_type
|
47
|
-
@current_migration_sections.map(&:content_type).include? content_type
|
48
|
-
end
|
49
|
-
|
50
|
-
def current_migration_section_of_content_type content_type
|
51
|
-
section = @current_migration_sections.find(&:content_type)
|
52
|
-
if section.nil?
|
53
|
-
raise SectionNotFoundError, "No section of type #{content_type} found"
|
54
|
-
end
|
55
|
-
section
|
56
|
-
end
|
57
|
-
|
58
|
-
# return true if the current migration only has the provided content types and comments
|
59
|
-
def current_migration_only_content_types? content_types
|
60
|
-
(@current_migration_sections.map(&:content_type) - content_types - [:comment]).empty?
|
61
|
-
end
|
62
|
-
|
63
|
-
def generate_current_migration_name
|
64
|
-
if current_migration_has_content_type? :create_schema
|
65
|
-
"create_#{current_migration_section_of_content_type(:create_schema).schema_name}_schema".to_sym
|
66
|
-
|
67
|
-
elsif current_migration_has_content_type? :drop_schema
|
68
|
-
"drop_#{current_migration_section_of_content_type(:drop_schema).schema_name}_schema".to_sym
|
69
|
-
|
70
|
-
elsif current_migration_has_content_type? :create_table
|
71
|
-
"create_#{current_migration_section_of_content_type(:create_table).table_name}".to_sym
|
72
|
-
|
73
|
-
elsif current_migration_has_content_type? :drop_table
|
74
|
-
"drop_#{current_migration_section_of_content_type(:drop_table).table_name}".to_sym
|
75
|
-
|
76
|
-
elsif current_migration_only_content_types? [:create_function]
|
77
|
-
"create_function_#{@current_migration_sections.find { |s| s.content_type == :create_function }&.object_name}".to_sym
|
78
|
-
|
79
|
-
elsif current_migration_only_content_types? [:create_function, :update_function, :drop_function, :set_function_comment, :remove_function_comment]
|
80
|
-
:schema_functions
|
81
|
-
|
82
|
-
elsif @current_migration_sections.first&.table_name
|
83
|
-
"changes_for_#{@current_migration_sections.first&.table_name}".to_sym
|
84
|
-
|
85
|
-
else
|
86
|
-
:changes
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|