imigrate 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +104 -0
- data/Rakefile +2 -0
- data/imigrate.gemspec +25 -0
- data/lib/generators/imigrate.rb +30 -0
- data/lib/generators/templates/data_migration.rb +8 -0
- data/lib/imigrate.rb +9 -0
- data/lib/imigrate/activerecord_ext.rb +19 -0
- data/lib/imigrate/railtie.rb +10 -0
- data/lib/imigrate/version.rb +3 -0
- data/lib/tasks/capistrano.rake +17 -0
- data/lib/tasks/databases.rake +60 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +39 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/data_migrator.rb +1 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/data/20150202182709_populate_user.rb +9 -0
- data/spec/dummy/db/data/20150202183455_populate_user2.rb +9 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20150202164939_create_user.rb +8 -0
- data/spec/dummy/db/migrate_test/20150202174939_modify_user.rb +5 -0
- data/spec/dummy/db/schema.rb +27 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/lib/generators/generator_spec.rb +17 -0
- data/spec/rake_tasks_spec.rb +147 -0
- data/spec/spec_helper.rb +18 -0
- metadata +181 -0
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(version: 20150202164939) do
|
15
|
+
|
16
|
+
create_table "data_migrations", id: false, force: true do |t|
|
17
|
+
t.string "version", null: false
|
18
|
+
end
|
19
|
+
|
20
|
+
add_index "data_migrations", ["version"], name: "unique_data_migrations", unique: true
|
21
|
+
|
22
|
+
create_table "users", force: true do |t|
|
23
|
+
t.string "first_name"
|
24
|
+
t.string "last_name"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
Binary file
|
File without changes
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require "generator_spec"
|
4
|
+
|
5
|
+
describe Imigrate::Generators::DataMigrationGenerator, type: :generator do
|
6
|
+
destination File.expand_path("../../../tmp", __FILE__)
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
prepare_destination
|
10
|
+
end
|
11
|
+
|
12
|
+
it "create the templated file" do
|
13
|
+
run_generator %w{toto}
|
14
|
+
assert_migration "db/data/toto.rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
describe 'rake tasks' do
|
5
|
+
|
6
|
+
### Helpers ###
|
7
|
+
def rails_app_root
|
8
|
+
"#{MIGRATOR_ROOT}/spec/dummy"
|
9
|
+
end
|
10
|
+
def debug(mes)
|
11
|
+
if ENV['DEBUG'] == 'true'
|
12
|
+
puts mes
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def insert_migration_test
|
17
|
+
FileUtils.copy_file("#{rails_app_root}/db/migrate_test/20150202174939_modify_user.rb", "#{rails_app_root}/db/migrate/20150202174939_modify_user.rb")
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_migration_and_db
|
21
|
+
FileUtils.remove_file("#{rails_app_root}/db/migrate/20150202174939_modify_user.rb")
|
22
|
+
exec_cmd('rake db:drop')
|
23
|
+
exec_cmd('git checkout db/schema.rb')
|
24
|
+
exec_cmd('rake db:setup')
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_data_versions
|
28
|
+
ActiveRecord::Base.establish_connection
|
29
|
+
res = ActiveRecord::Base.connection.execute('SELECT * from data_migrations').to_a.map{|r| r['version']}
|
30
|
+
debug "Result get_data_versions: #{res}"
|
31
|
+
res
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_versions
|
35
|
+
ActiveRecord::Base.establish_connection
|
36
|
+
res = ActiveRecord::Base.connection.execute('SELECT * from schema_migrations').to_a.map{|r| r['version']}
|
37
|
+
debug "Result get_versions: #{res}"
|
38
|
+
res
|
39
|
+
end
|
40
|
+
|
41
|
+
def exec_cmd(cmd)
|
42
|
+
cmd_final = "cd #{rails_app_root} && RAILS_ENV=test #{cmd}"
|
43
|
+
|
44
|
+
debug "Executing: #{cmd_final}"
|
45
|
+
res = `#{cmd_final}`
|
46
|
+
debug "Result: #{res}"
|
47
|
+
res
|
48
|
+
end
|
49
|
+
|
50
|
+
def rake(task)
|
51
|
+
exec_cmd("rake #{task}")
|
52
|
+
end
|
53
|
+
#### End Helpers ####
|
54
|
+
|
55
|
+
describe 'db:data:migrate' do
|
56
|
+
before do
|
57
|
+
DatabaseCleaner.clean
|
58
|
+
end
|
59
|
+
|
60
|
+
it "add an user" do
|
61
|
+
expect{rake('db:data:migrate')}.to change{User.count}.by (2)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "add version to data_migration" do
|
65
|
+
rake('db:data:migrate')
|
66
|
+
expect(get_data_versions.any?).to eq(true)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "does not change schema migration" do
|
70
|
+
expect{rake('db:data:migrate')}.to_not change{get_versions}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'db:migrate' do
|
75
|
+
before do
|
76
|
+
ActiveRecord::Base.establish_connection
|
77
|
+
DatabaseCleaner.clean
|
78
|
+
insert_migration_test
|
79
|
+
end
|
80
|
+
after do
|
81
|
+
reset_migration_and_db
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'does not add an user' do
|
85
|
+
expect{rake('db:migrate')}.to_not change{User.count}
|
86
|
+
end
|
87
|
+
|
88
|
+
it "does not add version to data_migration" do
|
89
|
+
rake('db:migrate')
|
90
|
+
expect(get_data_versions.any?).to eq(false)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "does add version to schema" do
|
94
|
+
rake('db:migrate')
|
95
|
+
expect(get_versions).to include('20150202174939')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'db:migrate:all' do
|
100
|
+
before do
|
101
|
+
ActiveRecord::Base.establish_connection
|
102
|
+
DatabaseCleaner.clean
|
103
|
+
insert_migration_test
|
104
|
+
end
|
105
|
+
after do
|
106
|
+
reset_migration_and_db
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'does add an user and change the schema' do
|
110
|
+
rake('db:migrate:all')
|
111
|
+
expect(User.count).to eq(2)
|
112
|
+
expect(get_versions).to include('20150202174939')
|
113
|
+
expect(get_data_versions).to include('20150202183455')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'setting an env_prefix' do
|
118
|
+
before do
|
119
|
+
ActiveRecord::Base.establish_connection
|
120
|
+
DatabaseCleaner.clean
|
121
|
+
insert_migration_test
|
122
|
+
end
|
123
|
+
after do
|
124
|
+
reset_migration_and_db
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'does add an user and change the schema' do
|
128
|
+
rake('DATA_MIGRATOR_ENV_PREFIX=staging db:migrate:all')
|
129
|
+
expect(User.count).to eq(2)
|
130
|
+
expect(get_versions).to include('20150202174939')
|
131
|
+
expect(get_data_versions).to include('staging_20150202183455')
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'when changing env_prefix' do
|
135
|
+
it 'contains version for both env' do
|
136
|
+
rake('DATA_MIGRATOR_ENV_PREFIX=staging db:data:migrate')
|
137
|
+
expect(get_data_versions).to include('staging_20150202183455')
|
138
|
+
expect(get_data_versions).to_not include('production_20150202183455')
|
139
|
+
expect(User.count).to eq(2)
|
140
|
+
rake('DATA_MIGRATOR_ENV_PREFIX=production db:data:migrate')
|
141
|
+
expect(get_data_versions).to include('staging_20150202183455')
|
142
|
+
expect(get_data_versions).to include('production_20150202183455')
|
143
|
+
expect(User.count).to eq(4)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= 'test'
|
2
|
+
|
3
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
4
|
+
|
5
|
+
require 'rails/test_help'
|
6
|
+
require 'rspec/rails'
|
7
|
+
require 'imigrate'
|
8
|
+
require 'database_cleaner'
|
9
|
+
|
10
|
+
MIGRATOR_ROOT = File.expand_path('../..', __FILE__)
|
11
|
+
|
12
|
+
DatabaseCleaner.strategy = :truncation
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
|
16
|
+
config.mock_with :rspec
|
17
|
+
|
18
|
+
end
|