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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e34615eda56bac536ac728a8edcddcec4cad606257a3fbb0769024a1837f0dc
4
- data.tar.gz: e54fb15d2400b5edf651678d4249b75cbeb014cfe4faa4fbfe6558f19af97e45
3
+ metadata.gz: dc7ce9fd6b89826b6a170f3a7cac65598170b96225b5e8957407558d5fbca61f
4
+ data.tar.gz: 5141c495a2b66ebd4e1d088f68f33f3ba85455827bb35437c96a2117e5c20127
5
5
  SHA512:
6
- metadata.gz: 67cef61d9e6dc3bcdc4d1b8f39cf3f4abf43917df38ec5b0f1503f0c275ae94d27501fd10a654eff5ee4ca4c4105bebc1db7031c77112b562a55be8127269893
7
- data.tar.gz: c511dc4230e52796249f9f5e260ccdef4c21b963b5564236ee2e601366efcc6823470711bc1116947cf9fe97f6ac1a0ec9d9341eee4fa713192be97aece7c762
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] - Unreleased
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.2.0.pre.1)
4
+ declare_schema (1.2.0)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # DeclareSchema
2
2
 
3
- Declare your Rails/active_record model schemas and have database migrations generated for you!
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
@@ -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
- 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
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("db/migrate/#{Time.now.to_i}_#{final_migration_name.underscore}.rb", migration_template.result(binding))
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.2.0.pre.1"
4
+ VERSION = "1.2.0"
5
5
  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
- existing = Dir["#{Rails.root}/db/migrate/*declare_schema_migration*"]
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
 
@@ -1,4 +1,4 @@
1
- class <%= @migration_class_name %> < (ActiveRecord::Migration[4.2])
1
+ class <%= @migration_class_name %> < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  <%= @up.presence or raise "no @up given!" %>
4
4
  end
@@ -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("(ActiveRecord::Migration[4.2])")
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.pre.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-09-13 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails