migration_data 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +0 -4
- data/lib/migration_data/version.rb +1 -1
- data/migration_data.gemspec +1 -1
- metadata +7 -17
- data/lib/migration_data/active_record/schema_dumper.rb +0 -16
- data/lib/migration_data/squash.rb +0 -49
- data/lib/tasks/db.rake +0 -11
- data/test/rake_task_test.rb +0 -49
- data/test/schema_dumper_test.rb +0 -20
- data/test/squash_test.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ea11a5103b28e5486a3e9568d4788036c2705d038648af2dba3ce67f97fef48
|
4
|
+
data.tar.gz: 476de225ff2914003630c272755e113e610b8b96729c9e1c02e4723a7037ed2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73c45622d5caace7a6841f556a6a10719722488fc63733aca8165e26c23cf61149707b053002c6de37ac67dd535d9a289ff80310b75e18eaa1ce4f24aaf45903
|
7
|
+
data.tar.gz: bb7b355049417e35eb0bb359111eace4be2b33faf0f3262be48c85b108331af214f5f2d628bb1798eb273e61cf0cbdb4dcd8cfc0b9c93cfea3df9c1a984807b5
|
data/README.md
CHANGED
@@ -83,10 +83,6 @@ end
|
|
83
83
|
|
84
84
|
The helper to load migrations `require_migration` is defined in the `migration_data/testing`. So you should to require it to have access to this convinient require extension.
|
85
85
|
|
86
|
-
## Clean old migration
|
87
|
-
|
88
|
-
Use `rake db:migrate:squash` to remove all your old migrations and generate one migration with the current database schema. You don't have to run migrations after this because the generated migration will have the latest database version.
|
89
|
-
|
90
86
|
## Contributing
|
91
87
|
|
92
88
|
1. Fork it ( http://github.com/ka8725/migration_data/fork )
|
data/migration_data.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
26
|
spec.add_development_dependency 'rake'
|
27
27
|
spec.add_development_dependency 'sqlite3'
|
28
28
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: migration_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Koleshko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,21 +72,15 @@ files:
|
|
72
72
|
- Rakefile
|
73
73
|
- lib/migration_data.rb
|
74
74
|
- lib/migration_data/active_record/migration.rb
|
75
|
-
- lib/migration_data/active_record/schema_dumper.rb
|
76
|
-
- lib/migration_data/squash.rb
|
77
75
|
- lib/migration_data/testing.rb
|
78
76
|
- lib/migration_data/version.rb
|
79
|
-
- lib/tasks/db.rake
|
80
77
|
- migration_data.gemspec
|
81
78
|
- test/db/20130906111511_test_migration.rb
|
82
79
|
- test/migration_test.rb
|
83
80
|
- test/rails_app/config/database.yml
|
84
81
|
- test/rails_app/db/migrate/0_create_schema.rb
|
85
82
|
- test/rails_app/db/test.sqlite3
|
86
|
-
- test/rake_task_test.rb
|
87
83
|
- test/require_migration_test.rb
|
88
|
-
- test/schema_dumper_test.rb
|
89
|
-
- test/squash_test.rb
|
90
84
|
- test/support/create_table_migration.rb
|
91
85
|
- test/support/rails_app.rb
|
92
86
|
- test/test_helper.rb
|
@@ -109,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
103
|
- !ruby/object:Gem::Version
|
110
104
|
version: '0'
|
111
105
|
requirements: []
|
112
|
-
|
113
|
-
rubygems_version: 2.5.1
|
106
|
+
rubygems_version: 3.1.2
|
114
107
|
signing_key:
|
115
108
|
specification_version: 4
|
116
109
|
summary: Provides possibility to write any code in migrations safely without regression.
|
@@ -120,10 +113,7 @@ test_files:
|
|
120
113
|
- test/rails_app/config/database.yml
|
121
114
|
- test/rails_app/db/migrate/0_create_schema.rb
|
122
115
|
- test/rails_app/db/test.sqlite3
|
123
|
-
- test/rake_task_test.rb
|
124
116
|
- test/require_migration_test.rb
|
125
|
-
- test/schema_dumper_test.rb
|
126
|
-
- test/squash_test.rb
|
127
117
|
- test/support/create_table_migration.rb
|
128
118
|
- test/support/rails_app.rb
|
129
119
|
- test/test_helper.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module MigrationData
|
2
|
-
module ActiveRecord
|
3
|
-
class SchemaDumper < ::ActiveRecord::SchemaDumper
|
4
|
-
def self.dump(connection=::ActiveRecord::Base.connection, stream=StringIO.new, config = ::ActiveRecord::Base)
|
5
|
-
new(connection, generate_options(config)).dump(stream)
|
6
|
-
stream
|
7
|
-
end
|
8
|
-
|
9
|
-
def dump(stream)
|
10
|
-
extensions(stream)
|
11
|
-
tables(stream)
|
12
|
-
stream
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'migration_data/active_record/schema_dumper'
|
2
|
-
|
3
|
-
module MigrationData
|
4
|
-
class Squash
|
5
|
-
def call
|
6
|
-
remove_all_old_migrations
|
7
|
-
squash_schema
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def squash_schema
|
13
|
-
File.open(migration_file_name, 'w') do |f|
|
14
|
-
content =
|
15
|
-
<<-MIGRATION.gsub(/^ {10}/, '')
|
16
|
-
class CreateSchema < ActiveRecord::Migration
|
17
|
-
def change
|
18
|
-
#{MigrationData::ActiveRecord::SchemaDumper.dump.string.strip.gsub(/^/, ' ')}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
MIGRATION
|
22
|
-
|
23
|
-
f.write(content)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def remove_all_old_migrations
|
28
|
-
migration_dirs.each do |dir|
|
29
|
-
FileUtils.rm_rf(Dir.glob(File.join(dir, '**/*.rb')))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def current_version
|
34
|
-
::ActiveRecord::Migrator.current_version
|
35
|
-
end
|
36
|
-
|
37
|
-
def migration_dirs
|
38
|
-
MigrationData::ActiveRecord::Migration.migration_dirs
|
39
|
-
end
|
40
|
-
|
41
|
-
def migration_dir
|
42
|
-
MigrationData::ActiveRecord::Migration.migration_dir
|
43
|
-
end
|
44
|
-
|
45
|
-
def migration_file_name
|
46
|
-
File.join(migration_dir, "#{current_version}_create_schema.rb")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/tasks/db.rake
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'migration_data/squash'
|
2
|
-
|
3
|
-
namespace :db do
|
4
|
-
namespace :migrate do
|
5
|
-
desc 'Squashes all current migrations and dumps current schema to the latest one'
|
6
|
-
task :squash => 'db:load_config' do
|
7
|
-
::ActiveRecord::Base.establish_connection
|
8
|
-
MigrationData::Squash.new.call
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
data/test/rake_task_test.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'migration_data/squash'
|
3
|
-
|
4
|
-
describe 'db:schema:squash' do
|
5
|
-
let(:rake) { Rake::Application.new }
|
6
|
-
|
7
|
-
def migrate_existing_migrations
|
8
|
-
CreateTableMigration.new.migrate(:up)
|
9
|
-
end
|
10
|
-
|
11
|
-
def load_rails_db_env
|
12
|
-
load 'active_record/railties/databases.rake'
|
13
|
-
Rake::Task['db:load_config'].invoke
|
14
|
-
end
|
15
|
-
|
16
|
-
def stub_dependent_tasks
|
17
|
-
rake.intern(Rake::Task, 'db:load_config')
|
18
|
-
end
|
19
|
-
|
20
|
-
def prepare_rake_env_for_testing
|
21
|
-
Rake.application = rake
|
22
|
-
Rake.application.rake_require('db', [File.expand_path('../../lib/tasks', __FILE__)])
|
23
|
-
end
|
24
|
-
|
25
|
-
before do
|
26
|
-
migrate_existing_migrations
|
27
|
-
load_rails_db_env
|
28
|
-
stub_dependent_tasks
|
29
|
-
prepare_rake_env_for_testing
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#invoke' do
|
33
|
-
it 'squashes the schema to the current migration' do
|
34
|
-
latest_migration = Rails.root.join('db', 'migrate', '0_create_schema.rb')
|
35
|
-
FileUtils.rm(latest_migration) if File.exist?(latest_migration)
|
36
|
-
|
37
|
-
Rake::Task['db:migrate:squash'].invoke
|
38
|
-
assert_equal <<-MIGRATION, File.read(latest_migration)
|
39
|
-
class CreateSchema < ActiveRecord::Migration
|
40
|
-
def change
|
41
|
-
create_table \"users\", force: #{FORCE_MIGRATION} do |t|
|
42
|
-
t.string \"name\"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
MIGRATION
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/test/schema_dumper_test.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'migration_data/active_record/schema_dumper'
|
3
|
-
|
4
|
-
describe MigrationData::ActiveRecord::SchemaDumper do
|
5
|
-
before do
|
6
|
-
CreateTableMigration.new.migrate(:up)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#dump' do
|
10
|
-
it 'squashes the schema' do
|
11
|
-
stream = MigrationData::ActiveRecord::SchemaDumper.dump
|
12
|
-
assert_equal <<-SCHEMA, stream.string
|
13
|
-
create_table \"users\", force: #{FORCE_MIGRATION} do |t|
|
14
|
-
t.string \"name\"
|
15
|
-
end
|
16
|
-
|
17
|
-
SCHEMA
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/test/squash_test.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'migration_data/squash'
|
3
|
-
|
4
|
-
describe MigrationData::Squash do
|
5
|
-
let(:squash) { MigrationData::Squash.new }
|
6
|
-
let(:db_path) { Rails.root.join('db', 'migrate') }
|
7
|
-
|
8
|
-
before do
|
9
|
-
CreateTableMigration.new.migrate(:up)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#call' do
|
13
|
-
it 'squashes the schema to the current migration' do
|
14
|
-
squash.stub(:current_version, '100500') do
|
15
|
-
squash.call
|
16
|
-
end
|
17
|
-
assert_equal <<-MIGRATION, File.read(db_path.join('100500_create_schema.rb'))
|
18
|
-
class CreateSchema < ActiveRecord::Migration
|
19
|
-
def change
|
20
|
-
create_table \"users\", force: #{FORCE_MIGRATION} do |t|
|
21
|
-
t.string \"name\"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
MIGRATION
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'removes all the old migrations' do
|
29
|
-
old_migration = db_path.join('100500_old_migration.rb')
|
30
|
-
File.write(old_migration, '')
|
31
|
-
|
32
|
-
assert_equal true, File.exist?(old_migration)
|
33
|
-
|
34
|
-
squash.call
|
35
|
-
|
36
|
-
assert_equal false, File.exist?(old_migration)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|