migration-export 1.0.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/Rakefile +12 -0
- data/lib/migration_export.rb +8 -0
- data/lib/migration_export/railtie.rb +13 -0
- data/lib/migration_export/tasks/db.rake +45 -0
- data/lib/migration_export/version.rb +11 -0
- data/migration-export.gemspec +22 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4dd7fa7a6b7fbbdc206fbe62072d58783cdec857
|
4
|
+
data.tar.gz: 942fb57546b66b73490a5708e825c1d25092a62e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7613fcc004a8d5532b2b406cdcf8549e96b56c966eef12776c6a7dc9c9d357c3ea7db0c34786c849d4b774cf85e43bfcf2384f6fb9cbd972b1d78e2bd87fcceb
|
7
|
+
data.tar.gz: 5aed0668a1f05813dec02014849105eb0621f46e7c65932148a3702d4a0fcbcfc5cb4fda45375c96fedb42b4404d0c7f54d4536f698c3d81ddf02735fc02c598
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'migration_export'
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
module MigrationExport end
|
6
|
+
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
|
9
|
+
rake_tasks do
|
10
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/*.rake')].each { |f| load f }
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'fileutils'
|
3
|
+
desc 'Migration export to sql file with name migration.sql'
|
4
|
+
namespace :db do
|
5
|
+
SQL_FILENAME = 'migrate.sql'
|
6
|
+
|
7
|
+
task migration_export: :environment do
|
8
|
+
create_file
|
9
|
+
|
10
|
+
CURRENT_VERSION = ActiveRecord::Base.connection.execute('select max(version) as version from schema_migrations').first['version']
|
11
|
+
|
12
|
+
ActiveRecord::Base.connection.class.class_eval do
|
13
|
+
alias_method :old_execute, :execute
|
14
|
+
|
15
|
+
def execute(sql, name = nil)
|
16
|
+
if /^(create|alter|drop|insert|delete|update)/i.match sql
|
17
|
+
File.open(SQL_FILENAME, 'a') { |f| f.puts "#{sql};\n" }
|
18
|
+
end
|
19
|
+
old_execute sql, name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Rake::Task['db:migrate'].invoke
|
24
|
+
|
25
|
+
File.open(SQL_FILENAME, 'a') do |f|
|
26
|
+
ActiveRecord::Migrator.migrations("#{Rails.root}/db/migrate").map do |t|
|
27
|
+
if t.version.to_i > CURRENT_VERSION.to_i
|
28
|
+
f.puts "INSERT INTO schema_migrations (version) VALUES ('#{t.version}'); "
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# migration for new database
|
35
|
+
task migration_export_db: :environment do
|
36
|
+
create_file
|
37
|
+
Rake::Task['db:structure:dump'].invoke
|
38
|
+
FileUtils.mv("#{Rails.root}/db/structure.sql", SQL_FILENAME)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_file
|
42
|
+
file = File.open(SQL_FILENAME, 'w')
|
43
|
+
file.close
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require './lib/migration_export/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'migration-export'
|
9
|
+
spec.version = MigrationExport::Version::STRING
|
10
|
+
spec.authors = ['Denis Nascimento', 'Magno Costa']
|
11
|
+
spec.email = ['denis@thssolution.com', 'magnocosta.br@gmail.com']
|
12
|
+
spec.description = spec.summary = 'Migration Export is a helper to export migration to sql file'
|
13
|
+
spec.homepage = 'https://github.com/fdnascimento/rails-migration-export'
|
14
|
+
|
15
|
+
spec.files = Dir['{lib/**/*.rake,lib/**/*.rb,README.rdoc,spec/**/*.rb,Rakefile,*.gemspec}']
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
20
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
21
|
+
spec.add_development_dependency 'pry', '~> 0'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: migration-export
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Denis Nascimento
|
8
|
+
- Magno Costa
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-02-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.6'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.6'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.4'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.4'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: Migration Export is a helper to export migration to sql file
|
57
|
+
email:
|
58
|
+
- denis@thssolution.com
|
59
|
+
- magnocosta.br@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- lib/migration_export/tasks/db.rake
|
65
|
+
- lib/migration_export/railtie.rb
|
66
|
+
- lib/migration_export/version.rb
|
67
|
+
- lib/migration_export.rb
|
68
|
+
- Rakefile
|
69
|
+
- migration-export.gemspec
|
70
|
+
homepage: https://github.com/fdnascimento/rails-migration-export
|
71
|
+
licenses: []
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.0.14.1
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Migration Export is a helper to export migration to sql file
|
93
|
+
test_files: []
|