declare_schema 1.2.0.pre.1 → 1.2.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: 8e34615eda56bac536ac728a8edcddcec4cad606257a3fbb0769024a1837f0dc
4
- data.tar.gz: e54fb15d2400b5edf651678d4249b75cbeb014cfe4faa4fbfe6558f19af97e45
3
+ metadata.gz: 9ba6099c2cfd605309415e3a14d53ba36aecad45285c4babdc385fa3576225ff
4
+ data.tar.gz: 60c009064977df314115e0bd1db8e811ba05866e24ac652a31b3ec4bc25291f5
5
5
  SHA512:
6
- metadata.gz: 67cef61d9e6dc3bcdc4d1b8f39cf3f4abf43917df38ec5b0f1503f0c275ae94d27501fd10a654eff5ee4ca4c4105bebc1db7031c77112b562a55be8127269893
7
- data.tar.gz: c511dc4230e52796249f9f5e260ccdef4c21b963b5564236ee2e601366efcc6823470711bc1116947cf9fe97f6ac1a0ec9d9341eee4fa713192be97aece7c762
6
+ metadata.gz: 9a7308b18a3a38c4713a2effb7f7f9dcf6b75702703152292061d4e266ada35b7be47e4ab43322965f9bfb0c88886ee138bea984bf0e09a9d37dde8bd1fe2da5
7
+ data.tar.gz: 10c67731046059b1ae1ff483ae979f4b649805deac4559ae2e4533082fa4e4a66e237814ff5873c638543ed533a5f660bf1dd204a5e3a8356fe377da1769d388
data/CHANGELOG.md CHANGED
@@ -4,11 +4,19 @@ 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.1] - 2022-09-25
8
+ ### Fixed
9
+ - If Rails is defined, raise if `Rails.application` is `nil`.
10
+
11
+ ## [1.2.0] - 2022-09-14
8
12
  ### Added
9
13
  - Added a rake task definition that can be optionally included into a non-Rails project to generate
10
14
  schema migrations.
11
15
 
16
+ ### Fixed
17
+ - Fixed a bug where not aliasing column names was allowing mysql to return them using their uppercase
18
+ variants
19
+
12
20
  ## [1.1.0] - 2022-07-22
13
21
  ### Changed
14
22
  - 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.
@@ -234,6 +242,7 @@ using the appropriate Rails configuration attributes.
234
242
  ### Added
235
243
  - Initial version from https://github.com/Invoca/hobo_fields v4.1.0.
236
244
 
245
+ [1.2.1]: https://github.com/Invoca/declare_schema/compare/v1.2.0...v1.2.1
237
246
  [1.2.0]: https://github.com/Invoca/declare_schema/compare/v1.1.0...v1.2.0
238
247
  [1.1.0]: https://github.com/Invoca/declare_schema/compare/v1.0.2...v1.1.0
239
248
  [1.0.2]: https://github.com/Invoca/declare_schema/compare/v1.0.1...v1.0.2
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.1)
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.1"
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
 
@@ -56,6 +55,7 @@ module Generators
56
55
  def load_rails_models
57
56
  ActiveRecord::Migration.verbose = false
58
57
  if defined?(Rails)
58
+ Rails.application or raise "Rails is defined, so Rails.application must be set"
59
59
  Rails.application.eager_load!
60
60
  Rails::Engine.subclasses.each(&:eager_load!)
61
61
  end
@@ -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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development adapted from hobo_fields by Tom Locke
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-13 00:00:00.000000000 Z
11
+ date: 2022-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -127,7 +127,7 @@ homepage: https://github.com/Invoca/declare_schema
127
127
  licenses: []
128
128
  metadata:
129
129
  allowed_push_host: https://rubygems.org
130
- post_install_message:
130
+ post_install_message:
131
131
  rdoc_options: []
132
132
  require_paths:
133
133
  - lib
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: 1.3.6
144
144
  requirements: []
145
145
  rubygems_version: 3.1.6
146
- signing_key:
146
+ signing_key:
147
147
  specification_version: 4
148
148
  summary: Database schema declaration and migration generator for Rails
149
149
  test_files: []