declare_schema 0.5.0 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/declare_schema_build.yml +60 -0
- data/.gitignore +1 -0
- data/Appraisals +21 -4
- data/CHANGELOG.md +46 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +4 -6
- data/README.md +3 -3
- data/Rakefile +17 -4
- data/bin/declare_schema +1 -1
- data/declare_schema.gemspec +1 -1
- data/gemfiles/rails_4_mysql.gemfile +22 -0
- data/gemfiles/{rails_4.gemfile → rails_4_sqlite.gemfile} +1 -2
- data/gemfiles/rails_5_mysql.gemfile +22 -0
- data/gemfiles/{rails_5.gemfile → rails_5_sqlite.gemfile} +1 -2
- data/gemfiles/rails_6_mysql.gemfile +22 -0
- data/gemfiles/{rails_6.gemfile → rails_6_sqlite.gemfile} +2 -3
- data/lib/declare_schema/command.rb +10 -3
- data/lib/declare_schema/model.rb +1 -1
- data/lib/declare_schema/model/field_spec.rb +18 -14
- data/lib/declare_schema/model/foreign_key_definition.rb +36 -25
- data/lib/declare_schema/model/table_options_definition.rb +8 -6
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +80 -34
- data/spec/lib/declare_schema/field_spec_spec.rb +69 -0
- data/spec/lib/declare_schema/generator_spec.rb +4 -2
- data/spec/lib/declare_schema/interactive_primary_key_spec.rb +8 -2
- data/spec/lib/declare_schema/migration_generator_spec.rb +286 -158
- data/spec/lib/declare_schema/model/foreign_key_definition_spec.rb +93 -0
- data/spec/lib/declare_schema/model/index_definition_spec.rb +4 -5
- data/spec/lib/declare_schema/model/table_options_definition_spec.rb +19 -29
- data/spec/lib/generators/declare_schema/migration/migrator_spec.rb +17 -22
- data/spec/support/acceptance_spec_helpers.rb +3 -3
- metadata +15 -10
- data/.travis.yml +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 523660550181d173c4ff4d6dc181b6d790419a3fdfb1e956076eed2d4c9f7f3b
|
4
|
+
data.tar.gz: '0380d2f800fd64c770c87631090ee792875034211b6ba9d18f5acc34e5ba9f0b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 824d98b6bb3b30d0eebf594db7cead5e954fed227eefdb8f627811da3a7f8c9bc76f62552c3c3a87b0ff3adf51a95a1e666e903d6993430aaa3521607b6ee260
|
7
|
+
data.tar.gz: e8b45fb7dd6df1b314b3ada7e3da6223c631911ce88233165dff486ddb0bfc4a09e42255c018e7d00a456f95d0c1a8af010fe5531f6c2d64516cf3a09f51eb19
|
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
on: [push]
|
3
|
+
|
4
|
+
name: DeclareSchema Build
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
name: DeclareSchema Build
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby: [ 2.4.5, 2.5.8, 2.6.5, 2.7.1 ]
|
13
|
+
gemfile:
|
14
|
+
- gemfiles/rails_4_mysql.gemfile
|
15
|
+
- gemfiles/rails_4_sqlite.gemfile
|
16
|
+
- gemfiles/rails_5_mysql.gemfile
|
17
|
+
- gemfiles/rails_5_sqlite.gemfile
|
18
|
+
- gemfiles/rails_6_mysql.gemfile
|
19
|
+
- gemfiles/rails_6_sqlite.gemfile
|
20
|
+
exclude:
|
21
|
+
- { gemfile: gemfiles/rails_4_mysql.gemfile, ruby: 2.7.1 }
|
22
|
+
- { gemfile: gemfiles/rails_4_sqlite.gemfile, ruby: 2.7.1 }
|
23
|
+
- { gemfile: gemfiles/rails_5_mysql.gemfile, ruby: 2.4.5 }
|
24
|
+
- { gemfile: gemfiles/rails_5_sqlite.gemfile, ruby: 2.4.5 }
|
25
|
+
- { gemfile: gemfiles/rails_6_mysql.gemfile, ruby: 2.4.5 }
|
26
|
+
- { gemfile: gemfiles/rails_6_sqlite.gemfile, ruby: 2.4.5 }
|
27
|
+
env:
|
28
|
+
BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
|
29
|
+
services:
|
30
|
+
mysql:
|
31
|
+
image: mysql:5.7
|
32
|
+
env:
|
33
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
34
|
+
ports:
|
35
|
+
- 3306:3306
|
36
|
+
steps:
|
37
|
+
- name: Checkout Branch
|
38
|
+
id: checkout_branch
|
39
|
+
uses: actions/checkout@v2
|
40
|
+
- name: Setup Ruby
|
41
|
+
id: setup_ruby
|
42
|
+
uses: ruby/setup-ruby@v1
|
43
|
+
with:
|
44
|
+
bundler: 1.17.3
|
45
|
+
ruby-version: ${{matrix.ruby}}
|
46
|
+
- name: Remove Bundler 2
|
47
|
+
id: remove_bundler_2
|
48
|
+
if: ${{ matrix.ruby >= '2.6.5' }}
|
49
|
+
run: |
|
50
|
+
rm -f /opt/hostedtoolcache/Ruby/2.*/x64/lib/ruby/gems/2.*/specifications/default/bundler-2.*.gemspec
|
51
|
+
gem install bundler:1.17.3 --force --default
|
52
|
+
gem install bundler -v 1.17.3
|
53
|
+
- name: Appraisals
|
54
|
+
id: appraisals
|
55
|
+
run: |
|
56
|
+
bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle} --gemfile=${{ matrix.gemfile }}
|
57
|
+
git config --global user.email "dummy@example.com"
|
58
|
+
git config --global user.name "dummy"
|
59
|
+
MYSQL_PORT=3306 bundle exec rake test:prepare_testapp[force]
|
60
|
+
bundle exec rake test:all < test_responses.txt
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
@@ -1,14 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
appraise 'rails-4' do
|
3
|
+
appraise 'rails-4-sqlite' do
|
4
4
|
gem 'rails', '~> 4.2'
|
5
5
|
gem 'sqlite3', '~> 1.3.0'
|
6
6
|
end
|
7
7
|
|
8
|
-
appraise 'rails-
|
8
|
+
appraise 'rails-4-mysql' do
|
9
|
+
gem 'rails', '~> 4.2'
|
10
|
+
gem 'mysql2'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'rails-5-sqlite' do
|
14
|
+
gem 'rails', '~> 5.2'
|
15
|
+
gem 'sqlite3'
|
16
|
+
end
|
17
|
+
|
18
|
+
appraise 'rails-5-mysql' do
|
9
19
|
gem 'rails', '~> 5.2'
|
20
|
+
gem 'mysql2'
|
21
|
+
end
|
22
|
+
|
23
|
+
appraise 'rails-6-sqlite' do
|
24
|
+
gem 'rails', '~> 6.1'
|
25
|
+
gem 'sqlite3'
|
10
26
|
end
|
11
27
|
|
12
|
-
appraise 'rails-6' do
|
13
|
-
gem 'rails', '~> 6.
|
28
|
+
appraise 'rails-6-mysql' do
|
29
|
+
gem 'rails', '~> 6.1'
|
30
|
+
gem 'mysql2'
|
14
31
|
end
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,47 @@ 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
|
+
## [0.6.4] - 2020-02-08
|
8
|
+
- Fixed a bug where the generated call to add_foreign_key() was not setting `column:`,
|
9
|
+
so it only worked in cases where Rails could infer the foreign key by convention.
|
10
|
+
|
11
|
+
## [0.6.3] - 2020-01-21
|
12
|
+
### Added
|
13
|
+
- Added `add_foreign_key` native rails call in `DeclareSchema::Model::ForeignKeyDefinition#to_add_statement`.
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
- Fixed a bug in migration generation caused by `DeclareSchema::Migration#create_constraints`
|
17
|
+
calling `DeclareSchema::Model::ForeignKeyDefinition#to_add_statement` with unused parameters.
|
18
|
+
|
19
|
+
- Fixed a bug in `DeclareSchema::Migration#remove_foreign_key` where special characters would not be quoted properly.
|
20
|
+
|
21
|
+
## [0.6.2] - 2021-01-06
|
22
|
+
### Added
|
23
|
+
- Added `sqlite3` as dev dependency for local development
|
24
|
+
|
25
|
+
### Fixed
|
26
|
+
- Fixed a bug in migration generation caused by `DeclareSchema::Model::ForeignKeyDefinition#to_add_statement`
|
27
|
+
not being passed proper arguments.
|
28
|
+
|
29
|
+
## [0.6.1] - 2021-01-06
|
30
|
+
### Added
|
31
|
+
- Added Appraisals for MySQL as well as SQLite.
|
32
|
+
|
33
|
+
### Fixed
|
34
|
+
- Fixed case where primary key index will be gone by the time we get to dropping that primary key
|
35
|
+
because all of the existing primary key columns are being removed.
|
36
|
+
|
37
|
+
## [0.6.0] - 2020-12-23
|
38
|
+
### Added
|
39
|
+
- Fields may now be declared with `:bigint` type which is identical to `:integer, limit 8`
|
40
|
+
- FieldSpec#initialize interface now includes `position` keyword argument and `**options` hash.
|
41
|
+
|
42
|
+
### Fixed
|
43
|
+
- Fixed cycle in which FieldSpec#initialize was calling `model.field_specs`
|
44
|
+
|
45
|
+
### Changed
|
46
|
+
- Changed ci support from Travis to Github Workflow
|
47
|
+
|
7
48
|
## [0.5.0] - 2020-12-21
|
8
49
|
### Added
|
9
50
|
- Added support for configuring the character set and collation for MySQL databases
|
@@ -73,6 +114,11 @@ using the appropriate Rails configuration attributes.
|
|
73
114
|
### Added
|
74
115
|
- Initial version from https://github.com/Invoca/hobo_fields v4.1.0.
|
75
116
|
|
117
|
+
[0.6.4]: https://github.com/Invoca/declare_schema/compare/v0.6.3...v0.6.4
|
118
|
+
[0.6.3]: https://github.com/Invoca/declare_schema/compare/v0.6.2...v0.6.3
|
119
|
+
[0.6.2]: https://github.com/Invoca/declare_schema/compare/v0.6.1...v0.6.2
|
120
|
+
[0.6.1]: https://github.com/Invoca/declare_schema/compare/v0.6.0...v0.6.1
|
121
|
+
[0.6.0]: https://github.com/Invoca/declare_schema/compare/v0.5.0...v0.6.0
|
76
122
|
[0.5.0]: https://github.com/Invoca/declare_schema/compare/v0.4.2...v0.5.0
|
77
123
|
[0.4.2]: https://github.com/Invoca/declare_schema/compare/v0.4.1...v0.4.2
|
78
124
|
[0.4.1]: https://github.com/Invoca/declare_schema/compare/v0.4.0...v0.4.1
|
data/Gemfile
CHANGED
@@ -14,10 +14,9 @@ gem 'bundler', '< 2'
|
|
14
14
|
gem "climate_control", '~> 0.2'
|
15
15
|
gem 'pry'
|
16
16
|
gem 'pry-byebug'
|
17
|
-
gem 'mysql2'
|
18
17
|
gem 'rails', '~> 5.2', '>= 5.2.4.3'
|
19
18
|
gem 'responders'
|
20
19
|
gem 'rspec'
|
21
20
|
gem 'rubocop'
|
22
|
-
gem 'sqlite3'
|
23
21
|
gem 'yard'
|
22
|
+
gem 'sqlite3', '~> 1.4'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
declare_schema (0.
|
4
|
+
declare_schema (0.6.4)
|
5
5
|
rails (>= 4.2)
|
6
6
|
|
7
7
|
GEM
|
@@ -64,12 +64,12 @@ GEM
|
|
64
64
|
crass (1.0.6)
|
65
65
|
diff-lcs (1.4.4)
|
66
66
|
erubi (1.9.0)
|
67
|
-
ffi (1.
|
67
|
+
ffi (1.14.2)
|
68
68
|
globalid (0.4.2)
|
69
69
|
activesupport (>= 4.2.0)
|
70
70
|
i18n (1.8.5)
|
71
71
|
concurrent-ruby (~> 1.0)
|
72
|
-
listen (3.
|
72
|
+
listen (3.4.1)
|
73
73
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
74
74
|
rb-inotify (~> 0.9, >= 0.9.10)
|
75
75
|
loofah (2.7.0)
|
@@ -85,7 +85,6 @@ GEM
|
|
85
85
|
mini_portile2 (2.4.0)
|
86
86
|
minitest (5.14.2)
|
87
87
|
msgpack (1.3.3)
|
88
|
-
mysql2 (0.5.3)
|
89
88
|
nio4r (2.5.4)
|
90
89
|
nokogiri (1.10.10)
|
91
90
|
mini_portile2 (~> 2.4.0)
|
@@ -188,14 +187,13 @@ DEPENDENCIES
|
|
188
187
|
climate_control (~> 0.2)
|
189
188
|
declare_schema!
|
190
189
|
listen
|
191
|
-
mysql2
|
192
190
|
pry
|
193
191
|
pry-byebug
|
194
192
|
rails (~> 5.2, >= 5.2.4.3)
|
195
193
|
responders
|
196
194
|
rspec
|
197
195
|
rubocop
|
198
|
-
sqlite3
|
196
|
+
sqlite3 (~> 1.4)
|
199
197
|
yard
|
200
198
|
|
201
199
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -94,7 +94,7 @@ turn all tables into `utf8mb4` supporting tables:
|
|
94
94
|
# frozen_string_literal: true
|
95
95
|
|
96
96
|
Generators::DeclareSchema::Migration::Migrator.default_charset = "utf8mb4"
|
97
|
-
Generators::DeclareSchema::Migration::Migrator.default_collation = "
|
97
|
+
Generators::DeclareSchema::Migration::Migrator.default_collation = "utf8mb4_bin"
|
98
98
|
```
|
99
99
|
|
100
100
|
### Table Configuration
|
@@ -109,7 +109,7 @@ like the following:
|
|
109
109
|
# frozen_string_literal: true
|
110
110
|
|
111
111
|
class Comment < ActiveRecord::Base
|
112
|
-
fields charset: "utf8mb4", collation: "
|
112
|
+
fields charset: "utf8mb4", collation: "utf8mb4_bin" do
|
113
113
|
subject :string, limit: 255
|
114
114
|
content :text, limit: 0xffff_ffff
|
115
115
|
end
|
@@ -131,7 +131,7 @@ look like the following:
|
|
131
131
|
class Comment < ActiveRecord::Base
|
132
132
|
fields do
|
133
133
|
subject :string, limit: 255
|
134
|
-
context :text, limit: 0xffff_ffff, charset: "utf8mb4", collation: "
|
134
|
+
context :text, limit: 0xffff_ffff, charset: "utf8mb4", collation: "utf8mb4_bin"
|
135
135
|
end
|
136
136
|
end
|
137
137
|
```
|
data/Rakefile
CHANGED
@@ -30,15 +30,28 @@ namespace "test" do
|
|
30
30
|
if args.force || !File.directory?(TESTAPP_PATH)
|
31
31
|
FileUtils.remove_entry_secure(TESTAPP_PATH, true)
|
32
32
|
sh %(#{BIN} new #{TESTAPP_PATH} --skip-wizard --skip-bundle)
|
33
|
-
FileUtils.chdir
|
33
|
+
FileUtils.chdir(TESTAPP_PATH)
|
34
|
+
begin
|
35
|
+
require 'mysql2'
|
36
|
+
if ENV['MYSQL_PORT']
|
37
|
+
sh "(echo 'H';
|
38
|
+
echo '1,$s/localhost/127.0.0.1/';
|
39
|
+
echo '/host:/';
|
40
|
+
echo 'a';
|
41
|
+
echo ' port: #{ENV['MYSQL_PORT']}';
|
42
|
+
echo '.';
|
43
|
+
echo w;
|
44
|
+
echo q) | ed #{TESTAPP_PATH}/config/database.yml || echo ed failed!"
|
45
|
+
end
|
46
|
+
rescue LoadError
|
47
|
+
end
|
34
48
|
sh "bundle install"
|
35
49
|
sh "(echo '';
|
36
|
-
echo \"gem '
|
37
|
-
echo \"gem 'therubyracer'\";
|
38
|
-
echo \"gem 'kramdown'\") > Gemfile"
|
50
|
+
echo \"gem 'irb', :group => :development\") >> Gemfile"
|
39
51
|
sh "echo '' > app/models/.gitignore" # because git reset --hard would rm the dir
|
40
52
|
rm ".gitignore" # we need to reset everything in a testapp
|
41
53
|
sh "git init && git add . && git commit -m \"initial commit\""
|
54
|
+
sh "rake db:create"
|
42
55
|
puts "The testapp has been created in '#{TESTAPP_PATH}'"
|
43
56
|
else
|
44
57
|
FileUtils.chdir(TESTAPP_PATH)
|
data/bin/declare_schema
CHANGED
data/declare_schema.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.authors = ['Invoca Development adapted from hobo_fields by Tom Locke']
|
7
7
|
s.email = 'development@invoca.com'
|
8
8
|
s.homepage = 'https://github.com/Invoca/declare_schema'
|
9
|
-
s.summary = 'Database migration generator for Rails'
|
9
|
+
s.summary = 'Database schema declaration and migration generator for Rails'
|
10
10
|
s.description = 'Declare your Rails/active_record model schemas and have database migrations generated for you!'
|
11
11
|
s.name = "declare_schema"
|
12
12
|
s.version = DeclareSchema::VERSION
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal"
|
6
|
+
gem "bundler", "< 2"
|
7
|
+
gem "climate_control", "~> 0.2"
|
8
|
+
gem "pry"
|
9
|
+
gem "pry-byebug"
|
10
|
+
gem "rails", "~> 4.2"
|
11
|
+
gem "responders"
|
12
|
+
gem "rspec"
|
13
|
+
gem "rubocop"
|
14
|
+
gem "yard"
|
15
|
+
gem "mysql2"
|
16
|
+
|
17
|
+
group :testapp do
|
18
|
+
gem "bootsnap", ">= 1.1.0", require: false
|
19
|
+
gem "listen"
|
20
|
+
end
|
21
|
+
|
22
|
+
gemspec path: "../"
|
@@ -7,13 +7,12 @@ gem "bundler", "< 2"
|
|
7
7
|
gem "climate_control", "~> 0.2"
|
8
8
|
gem "pry"
|
9
9
|
gem "pry-byebug"
|
10
|
-
gem "mysql2"
|
11
10
|
gem "rails", "~> 4.2"
|
12
11
|
gem "responders"
|
13
12
|
gem "rspec"
|
14
13
|
gem "rubocop"
|
15
|
-
gem "sqlite3", "~> 1.3.0"
|
16
14
|
gem "yard"
|
15
|
+
gem "sqlite3", "~> 1.3.0"
|
17
16
|
|
18
17
|
group :testapp do
|
19
18
|
gem "bootsnap", ">= 1.1.0", require: false
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal"
|
6
|
+
gem "bundler", "< 2"
|
7
|
+
gem "climate_control", "~> 0.2"
|
8
|
+
gem "pry"
|
9
|
+
gem "pry-byebug"
|
10
|
+
gem "rails", "~> 5.2"
|
11
|
+
gem "responders"
|
12
|
+
gem "rspec"
|
13
|
+
gem "rubocop"
|
14
|
+
gem "yard"
|
15
|
+
gem "mysql2"
|
16
|
+
|
17
|
+
group :testapp do
|
18
|
+
gem "bootsnap", ">= 1.1.0", require: false
|
19
|
+
gem "listen"
|
20
|
+
end
|
21
|
+
|
22
|
+
gemspec path: "../"
|
@@ -7,13 +7,12 @@ gem "bundler", "< 2"
|
|
7
7
|
gem "climate_control", "~> 0.2"
|
8
8
|
gem "pry"
|
9
9
|
gem "pry-byebug"
|
10
|
-
gem "mysql2"
|
11
10
|
gem "rails", "~> 5.2"
|
12
11
|
gem "responders"
|
13
12
|
gem "rspec"
|
14
13
|
gem "rubocop"
|
15
|
-
gem "sqlite3"
|
16
14
|
gem "yard"
|
15
|
+
gem "sqlite3"
|
17
16
|
|
18
17
|
group :testapp do
|
19
18
|
gem "bootsnap", ">= 1.1.0", require: false
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal"
|
6
|
+
gem "bundler", "< 2"
|
7
|
+
gem "climate_control", "~> 0.2"
|
8
|
+
gem "pry"
|
9
|
+
gem "pry-byebug"
|
10
|
+
gem "rails", "~> 6.1"
|
11
|
+
gem "responders"
|
12
|
+
gem "rspec"
|
13
|
+
gem "rubocop"
|
14
|
+
gem "yard"
|
15
|
+
gem "mysql2"
|
16
|
+
|
17
|
+
group :testapp do
|
18
|
+
gem "bootsnap", ">= 1.1.0", require: false
|
19
|
+
gem "listen"
|
20
|
+
end
|
21
|
+
|
22
|
+
gemspec path: "../"
|
@@ -7,13 +7,12 @@ gem "bundler", "< 2"
|
|
7
7
|
gem "climate_control", "~> 0.2"
|
8
8
|
gem "pry"
|
9
9
|
gem "pry-byebug"
|
10
|
-
gem "
|
11
|
-
gem "rails", "~> 6.0"
|
10
|
+
gem "rails", "~> 6.1"
|
12
11
|
gem "responders"
|
13
12
|
gem "rspec"
|
14
13
|
gem "rubocop"
|
15
|
-
gem "sqlite3"
|
16
14
|
gem "yard"
|
15
|
+
gem "sqlite3"
|
17
16
|
|
18
17
|
group :testapp do
|
19
18
|
gem "bootsnap", ">= 1.1.0", require: false
|
@@ -16,7 +16,7 @@ module DeclareSchema
|
|
16
16
|
EOS
|
17
17
|
|
18
18
|
class << self
|
19
|
-
def run(gem, args, version)
|
19
|
+
def run(gem, args, version, gemfile_options = {})
|
20
20
|
command = args.shift
|
21
21
|
|
22
22
|
case command
|
@@ -38,10 +38,17 @@ module DeclareSchema
|
|
38
38
|
end
|
39
39
|
template_path = File.join(Dir.tmpdir, "declare_schema_app_template")
|
40
40
|
File.open(template_path, 'w') do |file|
|
41
|
-
file.puts "gem '#{gem}', '>= #{version}'"
|
41
|
+
file.puts ["gem '#{gem}', '>= #{version}'", (gemfile_options.inspect unless gemfile_options.empty?)].compact.join(', ')
|
42
42
|
end
|
43
43
|
puts "Generating Rails infrastructure..."
|
44
|
-
|
44
|
+
database_option =
|
45
|
+
begin
|
46
|
+
require 'mysql2'
|
47
|
+
' -d mysql'
|
48
|
+
rescue LoadError
|
49
|
+
end
|
50
|
+
puts("rails new #{app_name} #{args * ' '} -m #{template_path}#{database_option}")
|
51
|
+
system("rails new #{app_name} #{args * ' '} -m #{template_path}#{database_option}")
|
45
52
|
File.delete(template_path)
|
46
53
|
|
47
54
|
when /^(g|generate|destroy)$/
|