declare_schema 1.2.0.pre.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- 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 +9 -19
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +2 -3
- data/lib/generators/declare_schema/migration/templates/migration.rb.erb +1 -1
- data/spec/lib/declare_schema/migration_generator_spec.rb +1 -1
- metadata +2 -2
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,11 +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] -
|
7
|
+
## [1.2.0] - 2022-09-14
|
8
8
|
### Added
|
9
9
|
- Added a rake task definition that can be optionally included into a non-Rails project to generate
|
10
10
|
schema migrations.
|
11
11
|
|
12
|
+
### Fixed
|
13
|
+
- Fixed a bug where not aliasing column names was allowing mysql to return them using their uppercase
|
14
|
+
variants
|
15
|
+
|
12
16
|
## [1.1.0] - 2022-07-22
|
13
17
|
### Changed
|
14
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.
|
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
|
data/lib/declare_schema/rake.rb
CHANGED
@@ -6,6 +6,10 @@ require "declare_schema/schema_change/column_remove"
|
|
6
6
|
require "generators/declare_schema/migration/migrator"
|
7
7
|
require "erb"
|
8
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
|
+
|
9
13
|
namespace :declare_schema do
|
10
14
|
desc 'Generate migrations for the database schema'
|
11
15
|
task :generate => 'db:load_config' do
|
@@ -24,29 +28,15 @@ namespace :declare_schema do
|
|
24
28
|
puts down
|
25
29
|
puts "----------------------------------"
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
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__)))
|
39
35
|
|
40
36
|
@up = " #{up.strip.split("\n").join("\n ")}"
|
41
37
|
@down = " #{down.strip.split("\n").join("\n ")}"
|
42
38
|
@migration_class_name = final_migration_name.camelize
|
43
39
|
|
44
|
-
File.write("
|
40
|
+
File.write("#{migration_root_directory}/#{Time.now.to_i}_#{final_migration_name.underscore}.rb", migration_template.result(binding))
|
45
41
|
end
|
46
42
|
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
|
@@ -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
|
|
@@ -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.2.0
|
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-09-
|
11
|
+
date: 2022-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|