declare_schema 1.1.0 → 1.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 +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +20 -6
- data/lib/declare_schema/model/column.rb +1 -1
- data/lib/declare_schema/model/table_options_definition.rb +1 -1
- data/lib/declare_schema/rake.rb +42 -0
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +6 -6
- data/lib/generators/declare_schema/migration/templates/migration.rb.erb +1 -1
- data/spec/lib/declare_schema/migration_generator_spec.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc7ce9fd6b89826b6a170f3a7cac65598170b96225b5e8957407558d5fbca61f
|
4
|
+
data.tar.gz: 5141c495a2b66ebd4e1d088f68f33f3ba85455827bb35437c96a2117e5c20127
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1edff05f2f7b5efbf7eeb8ce56e27b87744866b0c788795eaab0bd228fa700869a4dd13c4e38f47df18ee0ac67bd5eb091ae4df799b94adb1970edf572801c9a
|
7
|
+
data.tar.gz: 5d0e4633314231757af2bd1ae519eaff9714a91d6af4ca535ada1e9467067046e14c3db0bd7363cd1b20c8647526d64e2ab3ebf6503206f17e440503b7ebed34
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,15 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
5
5
|
Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.2.0] - 2022-09-14
|
8
|
+
### Added
|
9
|
+
- Added a rake task definition that can be optionally included into a non-Rails project to generate
|
10
|
+
schema migrations.
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- Fixed a bug where not aliasing column names was allowing mysql to return them using their uppercase
|
14
|
+
variants
|
15
|
+
|
7
16
|
## [1.1.0] - 2022-07-22
|
8
17
|
### Changed
|
9
18
|
- Fixed a bug where `DeclareSchema::Model::HabtmModelShim` `indexes` and `integer limits` were not being generated properly. Use `limit 8` for ids and primary composite key for habtm model.
|
@@ -229,6 +238,7 @@ using the appropriate Rails configuration attributes.
|
|
229
238
|
### Added
|
230
239
|
- Initial version from https://github.com/Invoca/hobo_fields v4.1.0.
|
231
240
|
|
241
|
+
[1.2.0]: https://github.com/Invoca/declare_schema/compare/v1.1.0...v1.2.0
|
232
242
|
[1.1.0]: https://github.com/Invoca/declare_schema/compare/v1.0.2...v1.1.0
|
233
243
|
[1.0.2]: https://github.com/Invoca/declare_schema/compare/v1.0.1...v1.0.2
|
234
244
|
[1.0.1]: https://github.com/Invoca/declare_schema/compare/v1.0.0...v1.0.1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# DeclareSchema
|
2
2
|
|
3
|
-
Declare your Rails/
|
3
|
+
Declare your Rails/ActiveRecord model schemas and have database migrations generated for you!
|
4
4
|
|
5
5
|
## Example
|
6
6
|
|
@@ -60,6 +60,20 @@ declare_schema id: :bigint do
|
|
60
60
|
end
|
61
61
|
```
|
62
62
|
|
63
|
+
## Usage without Rails
|
64
|
+
|
65
|
+
When using `DeclareSchema` without Rails, you can use the `declare_schema/rake` task to generate the migration file.
|
66
|
+
|
67
|
+
To do so, add the following require to your Rakefile:
|
68
|
+
```ruby
|
69
|
+
require 'declare_schema/rake'
|
70
|
+
```
|
71
|
+
|
72
|
+
Then, run the task:
|
73
|
+
```sh
|
74
|
+
rake declare_schema:generate
|
75
|
+
```
|
76
|
+
|
63
77
|
## Migrator Configuration
|
64
78
|
|
65
79
|
The following configuration options are available for the gem and can be used
|
@@ -117,7 +131,7 @@ declaration.
|
|
117
131
|
|
118
132
|
For example, adding the following to your `config/initializers` directory will
|
119
133
|
set the default `text limit` value to `0xffff`:
|
120
|
-
|
134
|
+
|
121
135
|
**declare_schema.rb**
|
122
136
|
```ruby
|
123
137
|
# frozen_string_literal: true
|
@@ -133,7 +147,7 @@ declaration.
|
|
133
147
|
|
134
148
|
For example, adding the following to your `config/initializers` directory will
|
135
149
|
set the default `string limit` value to `255`:
|
136
|
-
|
150
|
+
|
137
151
|
**declare_schema.rb**
|
138
152
|
```ruby
|
139
153
|
# frozen_string_literal: true
|
@@ -149,7 +163,7 @@ declaration.
|
|
149
163
|
|
150
164
|
For example, adding the following to your `config/initializers` directory will
|
151
165
|
set the default `null` value to `true`:
|
152
|
-
|
166
|
+
|
153
167
|
**declare_schema.rb**
|
154
168
|
```ruby
|
155
169
|
# frozen_string_literal: true
|
@@ -163,7 +177,7 @@ This value defaults to `true` and can only be set at the global level.
|
|
163
177
|
|
164
178
|
For example, adding the following to your `config/initializers` directory will set
|
165
179
|
the default `generate foreign keys` value to `false`:
|
166
|
-
|
180
|
+
|
167
181
|
**declare_schema.rb**
|
168
182
|
```ruby
|
169
183
|
# frozen_string_literal: true
|
@@ -177,7 +191,7 @@ This value defaults to `true` and can only be set at the global level.
|
|
177
191
|
|
178
192
|
For example, adding the following to your `config/initializers` directory will
|
179
193
|
set the default `generate indexing` value to `false`:
|
180
|
-
|
194
|
+
|
181
195
|
**declare_schema.rb**
|
182
196
|
```ruby
|
183
197
|
# frozen_string_literal: true
|
@@ -132,7 +132,7 @@ module DeclareSchema
|
|
132
132
|
database_name = connection.current_database
|
133
133
|
|
134
134
|
defaults = connection.select_one(<<~EOS)
|
135
|
-
SELECT C.character_set_name, C.collation_name
|
135
|
+
SELECT C.character_set_name as character_set_name, C.collation_name as collation_name
|
136
136
|
FROM information_schema.`COLUMNS` C
|
137
137
|
WHERE C.table_schema = '#{connection.quote_string(database_name)}' AND
|
138
138
|
C.table_name = '#{connection.quote_string(current_table_name)}' AND
|
@@ -27,7 +27,7 @@ module DeclareSchema
|
|
27
27
|
def mysql_table_options(connection, table_name)
|
28
28
|
database = connection.current_database
|
29
29
|
defaults = connection.select_one(<<~EOS) or raise "no defaults found for table #{table_name}"
|
30
|
-
SELECT CCSA.character_set_name, CCSA.collation_name
|
30
|
+
SELECT CCSA.character_set_name as character_set_name, CCSA.collation_name as collation_name
|
31
31
|
FROM information_schema.TABLES as T
|
32
32
|
JOIN information_schema.COLLATION_CHARACTER_SET_APPLICABILITY as CCSA
|
33
33
|
ON CCSA.collation_name = T.table_collation
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "declare_schema"
|
4
|
+
require "declare_schema/schema_change/all"
|
5
|
+
require "declare_schema/schema_change/column_remove"
|
6
|
+
require "generators/declare_schema/migration/migrator"
|
7
|
+
require "erb"
|
8
|
+
|
9
|
+
# This is a set of Rake tasks that can be used to generate migrations when using
|
10
|
+
# ActiveRecord, but not within a Rails application. If using Rails, you should
|
11
|
+
# use the built-in generators that come with the gem instead.
|
12
|
+
|
13
|
+
namespace :declare_schema do
|
14
|
+
desc 'Generate migrations for the database schema'
|
15
|
+
task :generate => 'db:load_config' do
|
16
|
+
up, down = Generators::DeclareSchema::Migration::Migrator.new(renames: {}).generate
|
17
|
+
|
18
|
+
if up.blank?
|
19
|
+
puts "Database and models match -- nothing to change"
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
puts "\n---------- Up Migration ----------"
|
24
|
+
puts up
|
25
|
+
puts "----------------------------------"
|
26
|
+
|
27
|
+
puts "\n---------- Down Migration --------"
|
28
|
+
puts down
|
29
|
+
puts "----------------------------------"
|
30
|
+
|
31
|
+
migration_root_directory = "db/migrate"
|
32
|
+
|
33
|
+
final_migration_name = Generators::DeclareSchema::Migration::Migrator.default_migration_name(Dir["#{migration_root_directory}/*declare_schema_migration*"])
|
34
|
+
migration_template = ERB.new(File.read(File.expand_path("../generators/declare_schema/migration/templates/migration.rb.erb", __dir__)))
|
35
|
+
|
36
|
+
@up = " #{up.strip.split("\n").join("\n ")}"
|
37
|
+
@down = " #{down.strip.split("\n").join("\n ")}"
|
38
|
+
@migration_class_name = final_migration_name.camelize
|
39
|
+
|
40
|
+
File.write("#{migration_root_directory}/#{Time.now.to_i}_#{final_migration_name.underscore}.rb", migration_template.result(binding))
|
41
|
+
end
|
42
|
+
end
|
@@ -28,9 +28,8 @@ module Generators
|
|
28
28
|
Migrator.new(renames: renames).generate
|
29
29
|
end
|
30
30
|
|
31
|
-
def default_migration_name
|
32
|
-
|
33
|
-
max = existing.grep(/([0-9]+)\.rb$/) { Regexp.last_match(1).to_i }.max.to_i
|
31
|
+
def default_migration_name(existing_migrations = Dir["#{Rails.root}/db/migrate/*declare_schema_migration*"])
|
32
|
+
max = existing_migrations.grep(/([0-9]+)\.rb$/) { Regexp.last_match(1).to_i }.max.to_i
|
34
33
|
"declare_schema_migration_#{max + 1}"
|
35
34
|
end
|
36
35
|
|
@@ -55,9 +54,10 @@ module Generators
|
|
55
54
|
|
56
55
|
def load_rails_models
|
57
56
|
ActiveRecord::Migration.verbose = false
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
if defined?(Rails)
|
58
|
+
Rails.application.eager_load!
|
59
|
+
Rails::Engine.subclasses.each(&:eager_load!)
|
60
|
+
end
|
61
61
|
self.class.before_generating_migration_callback&.call
|
62
62
|
end
|
63
63
|
|
@@ -1287,7 +1287,7 @@ RSpec.describe 'DeclareSchema Migration Generator' do
|
|
1287
1287
|
migration_content = File.read(migrations.first)
|
1288
1288
|
first_line = migration_content.split("\n").first
|
1289
1289
|
base_class = first_line.split(' < ').last
|
1290
|
-
expect(base_class).to eq("
|
1290
|
+
expect(base_class).to eq("ActiveRecord::Migration[4.2]")
|
1291
1291
|
end
|
1292
1292
|
end
|
1293
1293
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: declare_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca Development adapted from hobo_fields by Tom Locke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/declare_schema/model/index_definition.rb
|
68
68
|
- lib/declare_schema/model/table_options_definition.rb
|
69
69
|
- lib/declare_schema/railtie.rb
|
70
|
+
- lib/declare_schema/rake.rb
|
70
71
|
- lib/declare_schema/schema_change/all.rb
|
71
72
|
- lib/declare_schema/schema_change/base.rb
|
72
73
|
- lib/declare_schema/schema_change/column_add.rb
|
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
142
|
- !ruby/object:Gem::Version
|
142
143
|
version: 1.3.6
|
143
144
|
requirements: []
|
144
|
-
rubygems_version: 3.
|
145
|
+
rubygems_version: 3.1.6
|
145
146
|
signing_key:
|
146
147
|
specification_version: 4
|
147
148
|
summary: Database schema declaration and migration generator for Rails
|