liquigen 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +45 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +85 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/Rakefile +44 -0
- data/bin/liquigen +84 -0
- data/features/liquigen.feature +8 -0
- data/features/step_definitions/liquigen_steps.rb +6 -0
- data/features/support/env.rb +15 -0
- data/lib/liquigen.rb +15 -0
- data/lib/liquigen/change.rb +4 -0
- data/lib/liquigen/change_set.rb +14 -0
- data/lib/liquigen/column.rb +18 -0
- data/lib/liquigen/constraint.rb +11 -0
- data/lib/liquigen/create_table.rb +14 -0
- data/lib/liquigen/handlers/base.rb +88 -0
- data/lib/liquigen/handlers/create_table.rb +33 -0
- data/lib/liquigen/type_map.rb +30 -0
- data/lib/liquigen/version.rb +3 -0
- data/liquigen.gemspec +26 -0
- data/liquigen.rdoc +5 -0
- data/spec/liquigen/handler_spec.rb +54 -0
- data/spec/spec_helper.rb +14 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c01096e72134197d6aa01f609a9a7ea8d933329a5c260353bf40b833096d80c2
|
4
|
+
data.tar.gz: 787823a896e173df45e68a0cad0022d567116c37e428ca26e240eee33ab9e54a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a602ca2063d9e38f0b78a1c3b95c2a34fc0468aa6a944367b82bdb2e8da66413fc75a9b610f9f28ef57877a9e4e6a68bc5245fe0f29f3177fbe367cae2854418
|
7
|
+
data.tar.gz: 23fd4ea85cbb3ccc5d59c7f7487592d111c9fa36cf1cb218847d83ba284b048a84fcbfef2da0415a5eb389f76812502489654e3af3e7288c7a040e98ffce92b7
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'tmp/**/*'
|
4
|
+
|
5
|
+
Metrics/LineLength:
|
6
|
+
Max: 200
|
7
|
+
|
8
|
+
Metrics/MethodLength:
|
9
|
+
Max: 40
|
10
|
+
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Metrics/ClassLength:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/ModuleLength:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/AbcSize:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/AsciiComments:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Style/Documentation:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/FrozenStringLiteralComment:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/MixinGrouping:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/NumericPredicate:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/ClassAndModuleChildren:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/ParallelAssignment:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Style/SymbolArray:
|
45
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
liquigen (0.0.1)
|
5
|
+
activesupport
|
6
|
+
gli (= 2.18.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (5.2.1)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
aruba (0.14.6)
|
17
|
+
childprocess (>= 0.6.3, < 0.10.0)
|
18
|
+
contracts (~> 0.9)
|
19
|
+
cucumber (>= 1.3.19)
|
20
|
+
ffi (~> 1.9.10)
|
21
|
+
rspec-expectations (>= 2.99)
|
22
|
+
thor (~> 0.19)
|
23
|
+
backports (3.11.4)
|
24
|
+
builder (3.2.3)
|
25
|
+
childprocess (0.9.0)
|
26
|
+
ffi (~> 1.0, >= 1.0.11)
|
27
|
+
concurrent-ruby (1.0.5)
|
28
|
+
contracts (0.16.0)
|
29
|
+
cucumber (3.1.2)
|
30
|
+
builder (>= 2.1.2)
|
31
|
+
cucumber-core (~> 3.2.0)
|
32
|
+
cucumber-expressions (~> 6.0.1)
|
33
|
+
cucumber-wire (~> 0.0.1)
|
34
|
+
diff-lcs (~> 1.3)
|
35
|
+
gherkin (~> 5.1.0)
|
36
|
+
multi_json (>= 1.7.5, < 2.0)
|
37
|
+
multi_test (>= 0.1.2)
|
38
|
+
cucumber-core (3.2.1)
|
39
|
+
backports (>= 3.8.0)
|
40
|
+
cucumber-tag_expressions (~> 1.1.0)
|
41
|
+
gherkin (~> 5.0)
|
42
|
+
cucumber-expressions (6.0.1)
|
43
|
+
cucumber-tag_expressions (1.1.1)
|
44
|
+
cucumber-wire (0.0.1)
|
45
|
+
diff-lcs (1.3)
|
46
|
+
ffi (1.9.25)
|
47
|
+
gherkin (5.1.0)
|
48
|
+
gli (2.18.0)
|
49
|
+
i18n (1.1.1)
|
50
|
+
concurrent-ruby (~> 1.0)
|
51
|
+
minitest (5.11.3)
|
52
|
+
multi_json (1.13.1)
|
53
|
+
multi_test (0.1.2)
|
54
|
+
rake (10.5.0)
|
55
|
+
rdoc (6.0.4)
|
56
|
+
rspec (3.8.0)
|
57
|
+
rspec-core (~> 3.8.0)
|
58
|
+
rspec-expectations (~> 3.8.0)
|
59
|
+
rspec-mocks (~> 3.8.0)
|
60
|
+
rspec-core (3.8.0)
|
61
|
+
rspec-support (~> 3.8.0)
|
62
|
+
rspec-expectations (3.8.2)
|
63
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
64
|
+
rspec-support (~> 3.8.0)
|
65
|
+
rspec-mocks (3.8.0)
|
66
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
+
rspec-support (~> 3.8.0)
|
68
|
+
rspec-support (3.8.0)
|
69
|
+
thor (0.20.0)
|
70
|
+
thread_safe (0.3.6)
|
71
|
+
tzinfo (1.2.5)
|
72
|
+
thread_safe (~> 0.1)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
aruba
|
79
|
+
liquigen!
|
80
|
+
rake (~> 10.0)
|
81
|
+
rdoc
|
82
|
+
rspec (~> 3.0)
|
83
|
+
|
84
|
+
BUNDLED WITH
|
85
|
+
1.16.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jere
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# liquigen
|
2
|
+
|
3
|
+
Comparing with ruby, java sucks.
|
4
|
+
|
5
|
+
It is a simple tool for java liquibase script generation.
|
6
|
+
|
7
|
+
Only support mysql db and create_table currently. And it is not a perfect tool, only help to create basic content with simple name. Please change the generated content manually.
|
8
|
+
|
9
|
+
## how to use
|
10
|
+
1. Add **.ruby-version** to your java project directory. Fill the ruby version as the content, say, 2.5.1.
|
11
|
+
|
12
|
+
2. Add **.Gemfile** to the same directory.
|
13
|
+
|
14
|
+
``` ruby
|
15
|
+
source 'https://rubygems.org'
|
16
|
+
|
17
|
+
gem 'liquigen'
|
18
|
+
|
19
|
+
```
|
20
|
+
3. bundle install
|
21
|
+
|
22
|
+
4. Use the script to create database script.
|
23
|
+
|
24
|
+
## create_table
|
25
|
+
|
26
|
+
```bash
|
27
|
+
liquigen create_table -t table_name prop1:type prop2:type
|
28
|
+
|
29
|
+
# Example
|
30
|
+
liquigen create_table -t user id:integer name:string email:string created_time:datetime updated_time:datetime
|
31
|
+
```
|
32
|
+
The result file:
|
33
|
+
```yaml
|
34
|
+
databaseChangeLog:
|
35
|
+
- changeSet:
|
36
|
+
id: '20181103214403'
|
37
|
+
name: jeremy
|
38
|
+
changes:
|
39
|
+
- createTable:
|
40
|
+
tableName: users
|
41
|
+
columns:
|
42
|
+
- column:
|
43
|
+
name: id
|
44
|
+
type: bigint
|
45
|
+
constraints:
|
46
|
+
- constraint:
|
47
|
+
primaryKey: true
|
48
|
+
autoIncrement: true
|
49
|
+
- column:
|
50
|
+
name: name
|
51
|
+
type: varchar(255)
|
52
|
+
constraints:
|
53
|
+
- constraint:
|
54
|
+
nullable: false
|
55
|
+
|
56
|
+
```
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jerecui/liquigen.
|
60
|
+
|
61
|
+
License
|
62
|
+
The gem is available as open source under the terms of the MIT License.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubygems/package_task'
|
4
|
+
require 'rdoc/task'
|
5
|
+
require 'cucumber'
|
6
|
+
require 'cucumber/rake/task'
|
7
|
+
Rake::RDocTask.new do |rd|
|
8
|
+
rd.main = "README.rdoc"
|
9
|
+
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
10
|
+
rd.title = 'Your application title'
|
11
|
+
end
|
12
|
+
|
13
|
+
spec = eval(File.read('liquigen.gemspec'))
|
14
|
+
|
15
|
+
Gem::PackageTask.new(spec) do |pkg|
|
16
|
+
end
|
17
|
+
CUKE_RESULTS = 'results.html'
|
18
|
+
CLEAN << CUKE_RESULTS
|
19
|
+
desc 'Run features'
|
20
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
21
|
+
opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
|
22
|
+
opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
|
23
|
+
t.cucumber_opts = opts
|
24
|
+
t.fork = false
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Run features tagged as work-in-progress (@wip)'
|
28
|
+
Cucumber::Rake::Task.new('features:wip') do |t|
|
29
|
+
tag_opts = ' --tags ~@pending'
|
30
|
+
tag_opts = ' --tags @wip'
|
31
|
+
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
|
32
|
+
t.fork = false
|
33
|
+
end
|
34
|
+
|
35
|
+
task :cucumber => :features
|
36
|
+
task 'cucumber:wip' => 'features:wip'
|
37
|
+
task :wip => 'features:wip'
|
38
|
+
require 'rake/testtask'
|
39
|
+
Rake::TestTask.new do |t|
|
40
|
+
t.libs << "test"
|
41
|
+
t.test_files = FileList['test/*_test.rb']
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => [:test,:features]
|
data/bin/liquigen
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'gli'
|
3
|
+
require 'liquigen'
|
4
|
+
|
5
|
+
# begin # XXX: Remove this begin/rescue before distributing your app
|
6
|
+
# rescue LoadError
|
7
|
+
# STDERR.puts "In development, you need to use `bundle exec bin/liquigen` to run your app"
|
8
|
+
# STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
|
9
|
+
# STDERR.puts "Feel free to remove this message from bin/liquigen now"
|
10
|
+
# exit 64
|
11
|
+
# end
|
12
|
+
|
13
|
+
class App
|
14
|
+
extend GLI::App
|
15
|
+
|
16
|
+
program_desc 'Generating the liquibase script like rails migration'
|
17
|
+
|
18
|
+
version Liquigen::VERSION
|
19
|
+
|
20
|
+
subcommand_option_handling :normal
|
21
|
+
arguments :strict
|
22
|
+
|
23
|
+
desc 'add table script'
|
24
|
+
arg_name 'Describe arguments to add_table here'
|
25
|
+
command :add_table do |c|
|
26
|
+
c.desc 'table name'
|
27
|
+
c.default_value 'table'
|
28
|
+
c.flag :t
|
29
|
+
|
30
|
+
c.action do |_, options, props|
|
31
|
+
table = options[:t].underscore.singularize
|
32
|
+
handler = Liquigen::Handlers::CreateTable.new table, props
|
33
|
+
handler.process
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Describe modify_table here'
|
38
|
+
arg_name 'Describe arguments to modify_table here'
|
39
|
+
command :modify_table do |c|
|
40
|
+
c.action do |global_options,options,args|
|
41
|
+
puts "modify_table command ran"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'Describe drop_table here'
|
46
|
+
arg_name 'Describe arguments to drop_table here'
|
47
|
+
command :drop_table do |c|
|
48
|
+
c.action do |global_options,options,args|
|
49
|
+
puts "drop_table command ran"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
pre do |global,command,options,args|
|
54
|
+
# Pre logic here
|
55
|
+
# Return true to proceed; false to abort and not call the
|
56
|
+
# chosen command
|
57
|
+
# Use skips_pre before a command to skip this block
|
58
|
+
# on that command only
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
post do |global,command,options,args|
|
63
|
+
# Post logic here
|
64
|
+
# Use skips_post before a command to skip this
|
65
|
+
# block on that command only
|
66
|
+
end
|
67
|
+
|
68
|
+
on_error do |err|
|
69
|
+
if debugging?
|
70
|
+
STDERR.puts err.message
|
71
|
+
STDERR.puts err.backtrace.join( "\n" )
|
72
|
+
else
|
73
|
+
next if GLI::CustomExit === err
|
74
|
+
|
75
|
+
STDERR.puts err.message
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def debugging?
|
81
|
+
defined? Bundler
|
82
|
+
end
|
83
|
+
|
84
|
+
exit App.run(ARGV)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'aruba/cucumber'
|
2
|
+
|
3
|
+
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
4
|
+
LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
|
5
|
+
|
6
|
+
Before do
|
7
|
+
# Using "announce" causes massive warnings on 1.9.2
|
8
|
+
@puts = true
|
9
|
+
@original_rubylib = ENV['RUBYLIB']
|
10
|
+
ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
After do
|
14
|
+
ENV['RUBYLIB'] = @original_rubylib
|
15
|
+
end
|
data/lib/liquigen.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'liquigen/version.rb'
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/inflector'
|
5
|
+
|
6
|
+
require 'liquigen/create_table'
|
7
|
+
require 'liquigen/change_set'
|
8
|
+
require 'liquigen/change'
|
9
|
+
require 'liquigen/column'
|
10
|
+
require 'liquigen/constraint'
|
11
|
+
require 'liquigen/handlers/base'
|
12
|
+
require 'liquigen/handlers/create_table'
|
13
|
+
|
14
|
+
# Add requires for other files you add to your project here, so
|
15
|
+
# you just need to require this one file in your bin file
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Liquigen
|
2
|
+
class ChangeSet
|
3
|
+
attr_accessor :id
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :changes
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
self.id = Time.new.strftime('%Y%m%d%H%M%S')
|
9
|
+
# todo Get the current git config name
|
10
|
+
self.name = 'Jeremy'
|
11
|
+
self.changes = []
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'liquigen/type_map'
|
2
|
+
|
3
|
+
module Liquigen
|
4
|
+
class Column
|
5
|
+
attr_accessor :name
|
6
|
+
attr_accessor :type
|
7
|
+
|
8
|
+
attr_accessor :auto_increment
|
9
|
+
attr_accessor :constraints
|
10
|
+
|
11
|
+
def initialize(attributes = {})
|
12
|
+
self.name = attributes[:name]
|
13
|
+
self.type = TypeMap.new(attributes[:type]).db_type
|
14
|
+
|
15
|
+
self.constraints = []
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'liquigen/create_table'
|
2
|
+
require 'liquigen/change_set'
|
3
|
+
require 'liquigen/change'
|
4
|
+
require 'liquigen/column'
|
5
|
+
require 'liquigen/constraint'
|
6
|
+
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
module Liquigen::Handlers
|
10
|
+
class Base
|
11
|
+
attr_accessor :table
|
12
|
+
attr_accessor :props
|
13
|
+
attr_accessor :sets
|
14
|
+
|
15
|
+
def initialize(table, props)
|
16
|
+
self.table = table
|
17
|
+
self.props = props
|
18
|
+
self.sets = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def process
|
22
|
+
build_change_sets
|
23
|
+
|
24
|
+
file_path = build_file_name
|
25
|
+
File.open(file_path, 'w+') { |f| f.write(sets.to_yaml(indentation: 4)) }
|
26
|
+
|
27
|
+
process_lines file_path
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def action_name
|
33
|
+
'liquigen'
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_file_name
|
37
|
+
dir = 'src/main/resources/db/migrations'
|
38
|
+
|
39
|
+
dirname = File.dirname(dir)
|
40
|
+
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
41
|
+
|
42
|
+
"#{dir}/#{Time.new.strftime('%Y%m%d%H%M%S')}_#{action_name}#{table.capitalize}.yaml"
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_lines(file_path)
|
46
|
+
lines = read_lines_without_ruby_redundant_type file_path
|
47
|
+
lines = remove_lines_with_empty_value lines
|
48
|
+
lines = camelize_words lines
|
49
|
+
|
50
|
+
File.open(file_path, 'w+') { |f| f.write(lines.join("\n")) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def read_lines_without_ruby_redundant_type(file_path)
|
54
|
+
lines = []
|
55
|
+
File.readlines(file_path).each do |line|
|
56
|
+
if line.include?('!ruby/object:Liquigen::')
|
57
|
+
line = line.gsub '!ruby/object:Liquigen::', ''
|
58
|
+
line = line.rstrip + ":\n"
|
59
|
+
end
|
60
|
+
lines << line.rstrip
|
61
|
+
end
|
62
|
+
lines[0] = 'databaseChangeLog:'
|
63
|
+
lines << '' # make sure the last line is empty
|
64
|
+
lines
|
65
|
+
end
|
66
|
+
|
67
|
+
def remove_lines_with_empty_value(lines)
|
68
|
+
empty_marks = []
|
69
|
+
lines.each_with_index do |line, index|
|
70
|
+
parts = line.split(':')
|
71
|
+
next if parts.size > 1
|
72
|
+
next if line.include?('-')
|
73
|
+
next if line.strip.size.zero?
|
74
|
+
next if lines[index + 1].nil?
|
75
|
+
|
76
|
+
empty_marks << index unless lines[index + 1].include?('-')
|
77
|
+
end
|
78
|
+
|
79
|
+
lines.select.with_index { |_, i| !empty_marks.include?(i) }
|
80
|
+
end
|
81
|
+
|
82
|
+
def camelize_words(lines)
|
83
|
+
lines.map do |line|
|
84
|
+
line.gsub(/[\w^:]+/) { |x| x.camelize(:lower) }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'liquigen/handlers/base'
|
2
|
+
|
3
|
+
module Liquigen::Handlers
|
4
|
+
class CreateTable < Base
|
5
|
+
def action_name
|
6
|
+
'CreateTable'
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_change_sets
|
10
|
+
set = Liquigen::ChangeSet.new
|
11
|
+
change = Liquigen::CreateTable.new(table)
|
12
|
+
set.changes << change
|
13
|
+
props.each { |kv| change.columns << build_column(kv) }
|
14
|
+
sets << set
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_column(name_and_type)
|
18
|
+
kv = name_and_type.split(':')
|
19
|
+
column = Liquigen::Column.new(name: kv[0], type: kv[1])
|
20
|
+
|
21
|
+
constraint = Liquigen::Constraint.new
|
22
|
+
if column.name == 'id'
|
23
|
+
column.auto_increment = true
|
24
|
+
constraint.primary_key = true
|
25
|
+
else
|
26
|
+
constraint.nullable = false
|
27
|
+
end
|
28
|
+
|
29
|
+
column.constraints << constraint
|
30
|
+
column
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Liquigen
|
2
|
+
class TypeMap
|
3
|
+
attr_accessor :rails_type
|
4
|
+
attr_accessor :map
|
5
|
+
|
6
|
+
def set_map
|
7
|
+
# Only for mysql
|
8
|
+
# http://blog.ifyouseewendy.com/blog/2015/08/10/data-types-in-rails/
|
9
|
+
self.map = {
|
10
|
+
integer: 'bigint',
|
11
|
+
string: 'varchar(255)',
|
12
|
+
text: 'text',
|
13
|
+
float: 'float',
|
14
|
+
decimal: 'decimal',
|
15
|
+
datetime: 'datetime',
|
16
|
+
binary: 'blob',
|
17
|
+
boolean: 'tinyint(1)'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(type)
|
22
|
+
self.rails_type = type
|
23
|
+
set_map
|
24
|
+
end
|
25
|
+
|
26
|
+
def db_type
|
27
|
+
map[rails_type.to_sym]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/liquigen.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Ensure we require the local version and not one we might have installed already
|
2
|
+
require File.join([File.dirname(__FILE__), 'lib', 'liquigen', 'version.rb'])
|
3
|
+
spec = Gem::Specification.new do |s|
|
4
|
+
s.name = 'liquigen'
|
5
|
+
s.version = Liquigen::VERSION
|
6
|
+
s.author = 'Jeremy Cui'
|
7
|
+
s.email = 'tsuijy@gmail.com'
|
8
|
+
s.homepage = 'http://github.com/jerecui/liquigen'
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.summary = 'Simple tool for generating the liquibase script.'
|
11
|
+
s.files = `git ls-files`.split("
|
12
|
+
")
|
13
|
+
s.require_paths << 'lib'
|
14
|
+
# s.extra_rdoc_files = ['README.rdoc', 'liquigen.rdoc']
|
15
|
+
# s.rdoc_options << '--title' << 'liquigen' << '--main' << 'README.rdoc' << '-ri'
|
16
|
+
s.bindir = 'bin'
|
17
|
+
s.executables << 'liquigen'
|
18
|
+
|
19
|
+
s.add_dependency('activesupport')
|
20
|
+
s.add_development_dependency 'aruba'
|
21
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
s.add_development_dependency 'rdoc'
|
23
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
24
|
+
|
25
|
+
s.add_runtime_dependency 'gli', '2.18.0'
|
26
|
+
end
|
data/liquigen.rdoc
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Liquigen::Handler, type: :model do
|
4
|
+
let(:handler) { Liquigen::Handler.new 'User', 'id: integer' }
|
5
|
+
|
6
|
+
let(:source) {
|
7
|
+
'databaseChangeLog:
|
8
|
+
- ChangeSet:
|
9
|
+
id: 201811031330
|
10
|
+
name: Jeremy
|
11
|
+
changes:
|
12
|
+
- CreateTable:
|
13
|
+
table_name: user
|
14
|
+
columns:
|
15
|
+
- Column:
|
16
|
+
name: id
|
17
|
+
type:
|
18
|
+
constraints:
|
19
|
+
- Constraint:
|
20
|
+
nullable: false
|
21
|
+
primary_key:
|
22
|
+
|
23
|
+
'
|
24
|
+
}
|
25
|
+
describe '#remove_empty' do
|
26
|
+
let(:lines) { source.split("\n") }
|
27
|
+
subject { handler.send(:remove_empty, lines) }
|
28
|
+
|
29
|
+
it 'should remove the lines which contains empty value' do
|
30
|
+
ret = subject
|
31
|
+
|
32
|
+
expect(ret.size).to eq 15
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#camelize' do
|
37
|
+
let(:source) {
|
38
|
+
'- ChangeSet:
|
39
|
+
id: 201811031330
|
40
|
+
name: Jeremy
|
41
|
+
changes:
|
42
|
+
- CreateTable
|
43
|
+
table_name: user
|
44
|
+
|
45
|
+
'
|
46
|
+
}
|
47
|
+
let(:lines) { source.split("\n") }
|
48
|
+
|
49
|
+
it 'should camelize the lines' do
|
50
|
+
ret = handler.send(:camelize_lines, lines)
|
51
|
+
expect(ret[ret.size - 1]).to eq ' tableName: user'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'liquigen'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: liquigen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Cui
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aruba
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: gli
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.18.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.18.0
|
97
|
+
description:
|
98
|
+
email: tsuijy@gmail.com
|
99
|
+
executables:
|
100
|
+
- liquigen
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/liquigen
|
112
|
+
- features/liquigen.feature
|
113
|
+
- features/step_definitions/liquigen_steps.rb
|
114
|
+
- features/support/env.rb
|
115
|
+
- lib/liquigen.rb
|
116
|
+
- lib/liquigen/change.rb
|
117
|
+
- lib/liquigen/change_set.rb
|
118
|
+
- lib/liquigen/column.rb
|
119
|
+
- lib/liquigen/constraint.rb
|
120
|
+
- lib/liquigen/create_table.rb
|
121
|
+
- lib/liquigen/handlers/base.rb
|
122
|
+
- lib/liquigen/handlers/create_table.rb
|
123
|
+
- lib/liquigen/type_map.rb
|
124
|
+
- lib/liquigen/version.rb
|
125
|
+
- liquigen.gemspec
|
126
|
+
- liquigen.rdoc
|
127
|
+
- spec/liquigen/handler_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
homepage: http://github.com/jerecui/liquigen
|
130
|
+
licenses: []
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.7.7
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Simple tool for generating the liquibase script.
|
153
|
+
test_files: []
|