declare_schema 1.1.0 → 1.2.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/lib/declare_schema/rake.rb +52 -0
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +4 -3
- 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: 8e34615eda56bac536ac728a8edcddcec4cad606257a3fbb0769024a1837f0dc
|
4
|
+
data.tar.gz: e54fb15d2400b5edf651678d4249b75cbeb014cfe4faa4fbfe6558f19af97e45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67cef61d9e6dc3bcdc4d1b8f39cf3f4abf43917df38ec5b0f1503f0c275ae94d27501fd10a654eff5ee4ca4c4105bebc1db7031c77112b562a55be8127269893
|
7
|
+
data.tar.gz: c511dc4230e52796249f9f5e260ccdef4c21b963b5564236ee2e601366efcc6823470711bc1116947cf9fe97f6ac1a0ec9d9341eee4fa713192be97aece7c762
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ 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] - Unreleased
|
8
|
+
### Added
|
9
|
+
- Added a rake task definition that can be optionally included into a non-Rails project to generate
|
10
|
+
schema migrations.
|
11
|
+
|
7
12
|
## [1.1.0] - 2022-07-22
|
8
13
|
### Changed
|
9
14
|
- 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 +234,7 @@ using the appropriate Rails configuration attributes.
|
|
229
234
|
### Added
|
230
235
|
- Initial version from https://github.com/Invoca/hobo_fields v4.1.0.
|
231
236
|
|
237
|
+
[1.2.0]: https://github.com/Invoca/declare_schema/compare/v1.1.0...v1.2.0
|
232
238
|
[1.1.0]: https://github.com/Invoca/declare_schema/compare/v1.0.2...v1.1.0
|
233
239
|
[1.0.2]: https://github.com/Invoca/declare_schema/compare/v1.0.1...v1.0.2
|
234
240
|
[1.0.1]: https://github.com/Invoca/declare_schema/compare/v1.0.0...v1.0.1
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,52 @@
|
|
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
|
+
namespace :declare_schema do
|
10
|
+
desc 'Generate migrations for the database schema'
|
11
|
+
task :generate => 'db:load_config' do
|
12
|
+
up, down = Generators::DeclareSchema::Migration::Migrator.new(renames: {}).generate
|
13
|
+
|
14
|
+
if up.blank?
|
15
|
+
puts "Database and models match -- nothing to change"
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
puts "\n---------- Up Migration ----------"
|
20
|
+
puts up
|
21
|
+
puts "----------------------------------"
|
22
|
+
|
23
|
+
puts "\n---------- Down Migration --------"
|
24
|
+
puts down
|
25
|
+
puts "----------------------------------"
|
26
|
+
|
27
|
+
final_migration_name = default_migration_name
|
28
|
+
migration_template = ERB.new(<<~EOF.chomp)
|
29
|
+
# frozen_string_literal: true
|
30
|
+
class <%= @migration_class_name %> < (ActiveRecord::Migration[4.2])
|
31
|
+
def self.up
|
32
|
+
<%= @up.presence or raise "no @up given!" %>
|
33
|
+
end
|
34
|
+
def self.down
|
35
|
+
<%= @down.presence or raise "no @down given!" %>
|
36
|
+
end
|
37
|
+
end
|
38
|
+
EOF
|
39
|
+
|
40
|
+
@up = " #{up.strip.split("\n").join("\n ")}"
|
41
|
+
@down = " #{down.strip.split("\n").join("\n ")}"
|
42
|
+
@migration_class_name = final_migration_name.camelize
|
43
|
+
|
44
|
+
File.write("db/migrate/#{Time.now.to_i}_#{final_migration_name.underscore}.rb", migration_template.result(binding))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_migration_name
|
49
|
+
existing = Dir["db/migrate/*declare_schema_migration*"]
|
50
|
+
max = existing.grep(/([0-9]+)\.rb$/) { Regexp.last_match(1).to_i }.max.to_i
|
51
|
+
"declare_schema_migration_#{max + 1}"
|
52
|
+
end
|
@@ -55,9 +55,10 @@ module Generators
|
|
55
55
|
|
56
56
|
def load_rails_models
|
57
57
|
ActiveRecord::Migration.verbose = false
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
if defined?(Rails)
|
59
|
+
Rails.application.eager_load!
|
60
|
+
Rails::Engine.subclasses.each(&:eager_load!)
|
61
|
+
end
|
61
62
|
self.class.before_generating_migration_callback&.call
|
62
63
|
end
|
63
64
|
|
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.pre.1
|
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-13 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
|