dynamic_migrations 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0a6f800da284a67951749b309cfd74aff4a769ce0c60bfc6798b07dd0108f5d
4
- data.tar.gz: 5e07832f150f6362aaf982bcd701739747347d48d5d63176bd7c4f00e43b38a2
3
+ metadata.gz: cd85087e52878be82f2733bc12a2949cff8cd25b5b52a6b0e820e760ad7d8ea0
4
+ data.tar.gz: a22b55bec2b78053ccca5541eeb55b33c78007d01f5af22997b8498a8631fbbb
5
5
  SHA512:
6
- metadata.gz: 192e7713b23050b8087218e741dc5204141bdee1783015c2d100a4a8935584ba365fb9e34200c359128763ed619f93fa4289ba01f7f33c79c463745fef64f70a
7
- data.tar.gz: 4c02f5f6ec71c1d0795ad0f57d899a8bdd311809055e390959e80d9fc75ee98adf59ea5bcb7c44a60b460367ed9bb1a2f2642d1e70fc4d3d6a3ed30e05d7e929
6
+ metadata.gz: c5a4322f59ab8d3fd626136633f6a9e1faeab846fb3165257a216347d232a5ea44363e0d9b0fc4ebad8a128e05beb0a78e9cbefe6710d6312cd5d4326e976747
7
+ data.tar.gz: 387790fda8976ade419f384e70171e2a89c1392756d8aae4e5915230a90dcb27eaf1a256f241f55dc0296d31f67bee6c565528194bda0e97e0c849d18ea7e663
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.1](https://github.com/craigulliott/dynamic_migrations/compare/v1.1.0...v1.1.1) (2023-07-17)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * validating that new databases don't already exist and removing a debug print statement ([73bed2d](https://github.com/craigulliott/dynamic_migrations/commit/73bed2d6ab928c7a8f53b2aa17a188a77ed369e9))
9
+ * validating that new databases don't already exist and removing a debug print statement ([73bed2d](https://github.com/craigulliott/dynamic_migrations/commit/73bed2d6ab928c7a8f53b2aa17a188a77ed369e9))
10
+ * validating that new databases don't already exist and removing a debug print statement ([f4cfb1e](https://github.com/craigulliott/dynamic_migrations/commit/f4cfb1e81252ed967ad1a6d864d495c182ca908f))
11
+
12
+ ## [1.1.0](https://github.com/craigulliott/dynamic_migrations/compare/v1.0.0...v1.1.0) (2023-07-10)
13
+
14
+
15
+ ### Features
16
+
17
+ * storing and returning database structure objects in alphabetical order of their names ([1b3255b](https://github.com/craigulliott/dynamic_migrations/commit/1b3255b220349bfb63d7f72d990557a104131cf7))
18
+
3
19
  ## 1.0.0 (2023-07-05)
4
20
 
5
21
 
data/README.md CHANGED
@@ -33,7 +33,7 @@ Note, this gem depends on the postgres gem `pg`, which depends on the `libpq` pa
33
33
  # required for pg gem on apple silicon
34
34
  brew install libpq
35
35
  export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
36
- ``
36
+ ```
37
37
 
38
38
  ## Getting Started
39
39
 
@@ -19,10 +19,18 @@ module DynamicMigrations
19
19
  end
20
20
  included_target = self
21
21
  if included_target.is_a? Database
22
- @configured_schemas[schema_name] = Schema.new :configuration, included_target, schema_name
22
+ new_schema = @configured_schemas[schema_name] = Schema.new :configuration, included_target, schema_name
23
23
  else
24
24
  raise ModuleIncludedIntoUnexpectedTargetError, included_target
25
25
  end
26
+ # sort the hash so that the schemas are in alphabetical order by name
27
+ sorted_schemas = {}
28
+ @configured_schemas.keys.sort.each do |schema_name|
29
+ sorted_schemas[schema_name] = @configured_schemas[schema_name]
30
+ end
31
+ @configured_schemas = sorted_schemas
32
+ # return the new schema
33
+ new_schema
26
34
  end
27
35
 
28
36
  # returns the configured schema object for the provided schema name, and raises an
@@ -19,10 +19,18 @@ module DynamicMigrations
19
19
  end
20
20
  included_target = self
21
21
  if included_target.is_a? Database
22
- @loaded_schemas[schema_name] = Schema.new :database, included_target, schema_name
22
+ new_schema = @loaded_schemas[schema_name] = Schema.new :database, included_target, schema_name
23
23
  else
24
24
  raise ModuleIncludedIntoUnexpectedTargetError, included_target
25
25
  end
26
+ # sort the hash so that the schemas are in alphabetical order by name
27
+ sorted_schemas = {}
28
+ @loaded_schemas.keys.sort.each do |schema_name|
29
+ sorted_schemas[schema_name] = @loaded_schemas[schema_name]
30
+ end
31
+ @loaded_schemas = sorted_schemas
32
+ # return the new schema
33
+ new_schema
26
34
  end
27
35
 
28
36
  # returns the loaded schema object for the provided schema name, and raises an
@@ -44,10 +44,18 @@ module DynamicMigrations
44
44
  end
45
45
  included_target = self
46
46
  if included_target.is_a? Table
47
- @columns[column_name] = Column.new source, included_target, column_name, data_type, **column_options
47
+ new_column = @columns[column_name] = Column.new source, included_target, column_name, data_type, **column_options
48
48
  else
49
49
  raise ModuleIncludedIntoUnexpectedTargetError, included_target
50
50
  end
51
+ # sort the hash so that the columns are in alphabetical order by name
52
+ sorted_columns = {}
53
+ @columns.keys.sort.each do |column_name|
54
+ sorted_columns[column_name] = @columns[column_name]
55
+ end
56
+ @columns = sorted_columns
57
+ # return the new column
58
+ new_column
51
59
  end
52
60
  end
53
61
  end
@@ -48,10 +48,18 @@ module DynamicMigrations
48
48
  foreign_columns = foreign_column_names.map { |column_name| foreign_table.column column_name }
49
49
  included_target = self
50
50
  if included_target.is_a? Table
51
- @foreign_key_constraints[foreign_key_constraint_name] = ForeignKeyConstraint.new source, included_target, columns, foreign_table, foreign_columns, foreign_key_constraint_name, **foreign_key_constraint_options
51
+ new_foreign_key_constraint = @foreign_key_constraints[foreign_key_constraint_name] = ForeignKeyConstraint.new source, included_target, columns, foreign_table, foreign_columns, foreign_key_constraint_name, **foreign_key_constraint_options
52
52
  else
53
53
  raise ModuleIncludedIntoUnexpectedTargetError, included_target
54
54
  end
55
+ # sort the hash so that the foreign_key_constraints are in alphabetical order by name
56
+ sorted_foreign_key_constraints = {}
57
+ @foreign_key_constraints.keys.sort.each do |foreign_key_constraint_name|
58
+ sorted_foreign_key_constraints[foreign_key_constraint_name] = @foreign_key_constraints[foreign_key_constraint_name]
59
+ end
60
+ @foreign_key_constraints = sorted_foreign_key_constraints
61
+ # return the new foreign_key_constraint
62
+ new_foreign_key_constraint
55
63
  end
56
64
  end
57
65
  end
@@ -49,10 +49,18 @@ module DynamicMigrations
49
49
  include_columns = include_column_names.map { |column_name| column column_name }
50
50
  included_target = self
51
51
  if included_target.is_a? Table
52
- @indexes[index_name] = Index.new source, included_target, columns, index_name, include_columns: include_columns, **index_options
52
+ new_index = @indexes[index_name] = Index.new source, included_target, columns, index_name, include_columns: include_columns, **index_options
53
53
  else
54
54
  raise ModuleIncludedIntoUnexpectedTargetError, included_target
55
55
  end
56
+ # sort the hash so that the indexes are in alphabetical order by name
57
+ sorted_indexes = {}
58
+ @indexes.keys.sort.each do |index_name|
59
+ sorted_indexes[index_name] = @indexes[index_name]
60
+ end
61
+ @indexes = sorted_indexes
62
+ # return the new index
63
+ new_index
56
64
  end
57
65
  end
58
66
  end
@@ -45,10 +45,18 @@ module DynamicMigrations
45
45
  columns = column_names.map { |column_name| column column_name }
46
46
  included_target = self
47
47
  if included_target.is_a? Table
48
- @unique_constraints[unique_constraint_name] = UniqueConstraint.new source, included_target, columns, unique_constraint_name, **unique_constraint_options
48
+ new_unique_constraint = @unique_constraints[unique_constraint_name] = UniqueConstraint.new source, included_target, columns, unique_constraint_name, **unique_constraint_options
49
49
  else
50
50
  raise ModuleIncludedIntoUnexpectedTargetError, included_target
51
51
  end
52
+ # sort the hash so that the unique_constraints are in alphabetical order by name
53
+ sorted_unique_constraints = {}
54
+ @unique_constraints.keys.sort.each do |unique_constraint_name|
55
+ sorted_unique_constraints[unique_constraint_name] = @unique_constraints[unique_constraint_name]
56
+ end
57
+ @unique_constraints = sorted_unique_constraints
58
+ # return the new unique_constraint
59
+ new_unique_constraint
52
60
  end
53
61
  end
54
62
  end
@@ -45,10 +45,18 @@ module DynamicMigrations
45
45
  columns = column_names.map { |column_name| column column_name }
46
46
  included_target = self
47
47
  if included_target.is_a? Table
48
- @validations[validation_name] = Validation.new source, included_target, columns, validation_name, check_clause, **validation_options
48
+ new_validation = @validations[validation_name] = Validation.new source, included_target, columns, validation_name, check_clause, **validation_options
49
49
  else
50
50
  raise ModuleIncludedIntoUnexpectedTargetError, included_target
51
51
  end
52
+ # sort the hash so that the validations are in alphabetical order by name
53
+ sorted_validations = {}
54
+ @validations.keys.sort.each do |validation_name|
55
+ sorted_validations[validation_name] = @validations[validation_name]
56
+ end
57
+ @validations = sorted_validations
58
+ # return the new validation
59
+ new_validation
52
60
  end
53
61
  end
54
62
  end
@@ -38,10 +38,18 @@ module DynamicMigrations
38
38
  end
39
39
  included_target = self
40
40
  if included_target.is_a? Schema
41
- @tables[table_name] = Table.new source, included_target, table_name, description
41
+ new_table = @tables[table_name] = Table.new source, included_target, table_name, description
42
42
  else
43
43
  raise ModuleIncludedIntoUnexpectedTargetError, included_target
44
44
  end
45
+ # sort the hash so that the tables are in alphabetical order by name
46
+ sorted_tables = {}
47
+ @tables.keys.sort.each do |table_name|
48
+ sorted_tables[table_name] = @tables[table_name]
49
+ end
50
+ @tables = sorted_tables
51
+ # return the new table
52
+ new_table
45
53
  end
46
54
 
47
55
  # return a table by its name, raises an error if the table does not exist
@@ -4,6 +4,9 @@ module DynamicMigrations
4
4
  module Postgres
5
5
  # This class represents a postgres server. A server can contain many databases.
6
6
  class Server
7
+ class DatabaseAlreadyExistsError < StandardError
8
+ end
9
+
7
10
  attr_reader :host, :port, :username, :password
8
11
 
9
12
  # initialize a new object to represent a postgres server
@@ -17,6 +20,7 @@ module DynamicMigrations
17
20
 
18
21
  def add_database database_name
19
22
  raise ExpectedSymbolError, database_name unless database_name.is_a? Symbol
23
+ raise DatabaseAlreadyExistsError, "database `#{database_name}` already exists" if @databases.key? database_name
20
24
  @databases[database_name] = Database.new self, database_name
21
25
  end
22
26
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamicMigrations
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Ulliott
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-05 00:00:00.000000000 Z
11
+ date: 2023-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pg_spec_helper
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  description: Monitor and generate database migrations based on difference between
42
56
  current schema and configuration
43
57
  email:
@@ -85,13 +99,13 @@ files:
85
99
  - lib/dynamic_migrations/postgres/server/database/structure_loader.rb
86
100
  - lib/dynamic_migrations/postgres/server/database/validations_loader.rb
87
101
  - lib/dynamic_migrations/version.rb
88
- homepage:
102
+ homepage:
89
103
  licenses:
90
104
  - MIT
91
105
  metadata:
92
106
  source_code_uri: https://github.com/craigulliott/dynamic_migrations/
93
107
  changelog_uri: https://github.com/craigulliott/dynamic_migrations/blob/main/CHANGELOG.md
94
- post_install_message:
108
+ post_install_message:
95
109
  rdoc_options: []
96
110
  require_paths:
97
111
  - lib
@@ -106,8 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
120
  - !ruby/object:Gem::Version
107
121
  version: '0'
108
122
  requirements: []
109
- rubygems_version: 3.3.26
110
- signing_key:
123
+ rubygems_version: 3.2.3
124
+ signing_key:
111
125
  specification_version: 4
112
126
  summary: Manage your database schema through configuration
113
127
  test_files: []