rack-app-sequel 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rack/app/sequel.rb +1 -0
- data/lib/rack/app/sequel/migration/cli.rb +4 -71
- data/lib/rack/app/sequel/migration/cli/migrate.rb +10 -0
- data/lib/rack/app/sequel/migration/cli/rollback.rb +9 -0
- data/lib/rack/app/sequel/migration/cli/template.rb +21 -0
- data/lib/rack/app/sequel/migration/cli/version.rb +15 -0
- data/lib/rack/app/sequel/runner.rb +79 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 914f7c22acd4f1ce23ba7f19fb6954cd8af04495
|
4
|
+
data.tar.gz: 5d34c4c7622b903f18c8df1b9ea23a85ea6b4a88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 540109421ffb84f45c9f4578f90e35e80e66ba48b8a93227a0908604a654b61a23775006e65999509543f142a7c5c06a06c7ab6fd227428166084a5451611ed1
|
7
|
+
data.tar.gz: d56fc9162254defaa5a1a68d9927442040852b62e7f1116d0e7d4d5a08dc61686c246473589f9b27e70996035e6f6f6d18d5e2929c27760edc3b04cfd94db610
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/rack/app/sequel.rb
CHANGED
@@ -1,74 +1,7 @@
|
|
1
1
|
Rack::App::SeQueL::Migration::CLI = lambda do
|
2
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'cli', '*.rb')).each do |file_path|
|
3
|
+
next if File.directory?(file_path)
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
option '-v', '--version [TIMESTAMP]', 'set to what db migration version number should db to be set' do |string|
|
7
|
-
options[:version] = string
|
8
|
-
end
|
9
|
-
|
10
|
-
option '--allow-missing-migration-files', 'In some cases, you may want to allow a migration in the database that does not exist in the filesystem' do
|
11
|
-
options[:allow_missing_migration_files] = true
|
12
|
-
end
|
13
|
-
|
14
|
-
option '-m', '--path-to-migration-patches [DIR_PATH]', "set to check what directory should be used for db migrations (default: #{Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY})" do |string|
|
15
|
-
options[:migration_directory] = string
|
16
|
-
end
|
17
|
-
|
18
|
-
option '--verbose', 'set migration to be verbose instead of silent' do
|
19
|
-
options[:verbose] = true
|
20
|
-
end
|
21
|
-
|
22
|
-
action do
|
23
|
-
|
24
|
-
options[:migration_directory] ||= Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY
|
25
|
-
|
26
|
-
Sequel.extension(:migration)
|
27
|
-
db = Rack::App::SeQueL.open_connection
|
28
|
-
db = Sequel.connect(ENV.fetch('DATABASE_URL'))
|
29
|
-
|
30
|
-
logger = Logger.new(options[:verbose] ? ::STDOUT : ::IO::NULL)
|
31
|
-
db.loggers << logger
|
32
|
-
|
33
|
-
migration_config = {}
|
34
|
-
if options[:allow_missing_migration_files]
|
35
|
-
migration_config[:allow_missing_migration_files]= true
|
36
|
-
end
|
37
|
-
|
38
|
-
if options[:version]
|
39
|
-
logger.info("Migrating to version #{options[:version]}")
|
40
|
-
|
41
|
-
migration_config[:target]= options[:version].to_i
|
42
|
-
end
|
43
|
-
|
44
|
-
Sequel::Migrator.run(db, options[:migration_directory], migration_config)
|
45
|
-
|
46
|
-
logger.info('Migration completed')
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
command "db:migration:create" do
|
52
|
-
description 'create migration patch'
|
53
|
-
|
54
|
-
option '-m', '--path-to-migration-patches [DIR_PATH]', "set to check what directory should be used for db migrations (default: #{Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY})" do |string|
|
55
|
-
options[:migration_directory] = string
|
56
|
-
end
|
57
|
-
|
58
|
-
action do |*name_parts|
|
59
|
-
options[:migration_directory] ||= Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY
|
60
|
-
name = name_parts.join('_')
|
61
|
-
|
62
|
-
require 'fileutils'
|
63
|
-
FileUtils.mkdir_p(options[:migration_directory])
|
64
|
-
timestamp = Time.now.to_i
|
65
|
-
filebasename = [timestamp.to_s, name].join('_') + '.rb'
|
66
|
-
file_path = File.join(options[:migration_directory], filebasename)
|
67
|
-
File.write(file_path, Rack::App::SeQueL::Migration::TEMPLATE)
|
68
|
-
|
69
|
-
STDOUT.puts(file_path)
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
5
|
+
instance_eval(File.read(file_path))
|
6
|
+
end
|
74
7
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
command 'db:migrate' do
|
2
|
+
|
3
|
+
description 'Migrates the supplied database using the migration files in the specified directory'
|
4
|
+
Rack::App::SeQueL::Runner.setup_command(self)
|
5
|
+
|
6
|
+
action do
|
7
|
+
exit(Rack::App::SeQueL::Runner.new(options, migration_config).run)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# command 'db:rollback' do
|
2
|
+
# description "Perform rollback to specified target or full rollback as default"
|
3
|
+
# Rack::App::SeQueL::Runner.setup_command(self)
|
4
|
+
|
5
|
+
# action do
|
6
|
+
# exit(Rack::App::SeQueL::Runner.new(options, migration_config).run)
|
7
|
+
# end
|
8
|
+
|
9
|
+
# end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
command 'db:migration:create' do
|
2
|
+
description 'create migration patch'
|
3
|
+
|
4
|
+
option '-m', '--path-to-migration-patches [DIR_PATH]', "set to check what directory should be used for db migrations (default: #{Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY})" do |string|
|
5
|
+
options[:migration_directory] = string
|
6
|
+
end
|
7
|
+
|
8
|
+
action do |*name_parts|
|
9
|
+
options[:migration_directory] ||= Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY
|
10
|
+
name = name_parts.join('_')
|
11
|
+
|
12
|
+
require 'fileutils'
|
13
|
+
FileUtils.mkdir_p(options[:migration_directory])
|
14
|
+
timestamp = Time.now.to_i
|
15
|
+
filebasename = [timestamp.to_s, name].join('_') + '.rb'
|
16
|
+
file_path = File.join(options[:migration_directory], filebasename)
|
17
|
+
File.write(file_path, Rack::App::SeQueL::Migration::TEMPLATE)
|
18
|
+
|
19
|
+
STDOUT.puts(file_path)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# command 'db:schema:version' do
|
2
|
+
# description 'prints current schema version'
|
3
|
+
|
4
|
+
# action do
|
5
|
+
# Sequel.extension(:migration)
|
6
|
+
# db = Rack::App::SeQueL.open_connection
|
7
|
+
# db = Sequel.connect(ENV.fetch('DATABASE_URL'))
|
8
|
+
|
9
|
+
# version = if db.tables.include?(:schema_info)
|
10
|
+
# db[:schema_info].first[:version]
|
11
|
+
# end || 0
|
12
|
+
|
13
|
+
# STDOUT.puts("Schema Version: #{version}")
|
14
|
+
# end
|
15
|
+
# end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class Rack::App::SeQueL::Runner
|
2
|
+
|
3
|
+
def self.setup_command(command)
|
4
|
+
command.class_eval do
|
5
|
+
|
6
|
+
option '-a', '--allow_missing_migration_files', 'In some cases, you may want to allow a migration in the database that does not exist in the filesystem' do
|
7
|
+
migration_config[:allow_missing_migration_files] = true
|
8
|
+
end
|
9
|
+
|
10
|
+
option '-c', '--current [CURRENT_VERION]', 'Set the current version of the database for the execution' do |current_database_version|
|
11
|
+
migration_config[:current] = current_database_version
|
12
|
+
end
|
13
|
+
|
14
|
+
# option '-r', '--relative [MIGRATION_COUNT]', 'Run the given number of migrations, with a positive number being migrations to migrate up, and a negative number being migrations to migrate down (IntegerMigrator only).' do |value|
|
15
|
+
# migration_config[:relative] = value.to_i
|
16
|
+
# end
|
17
|
+
|
18
|
+
option '-t', '--target [TIMESTAMP]', 'The target version to which to migrate. If not given, migrates to the maximum version.' do |target_version|
|
19
|
+
migration_config[:target] = target_version
|
20
|
+
end
|
21
|
+
|
22
|
+
option '-m', '--path-to-migration-patches [DIR_PATH]', "set to check what directory should be used for db migrations (default: #{Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY})" do |new_migration_directory|
|
23
|
+
options[:migration_directory] = new_migration_directory
|
24
|
+
end
|
25
|
+
|
26
|
+
option '-v', '--verbose', 'set migration to be verbose instead of silent' do
|
27
|
+
options[:verbose] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def migration_config
|
33
|
+
@migration_config ||= {}
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :code
|
40
|
+
|
41
|
+
def initialize(options, migration_options)
|
42
|
+
@code = 0
|
43
|
+
@options = options
|
44
|
+
@migration_options = migration_options
|
45
|
+
end
|
46
|
+
|
47
|
+
def run
|
48
|
+
Sequel.extension(:migration)
|
49
|
+
|
50
|
+
Rack::App::SeQueL.open_connection do |db|
|
51
|
+
db.loggers << logger
|
52
|
+
|
53
|
+
run_migrator(db, migration_directory, migration_config)
|
54
|
+
end
|
55
|
+
|
56
|
+
return @code
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def logger
|
62
|
+
@logger ||= Logger.new(@options[:verbose] ? ::STDOUT : ::IO::NULL)
|
63
|
+
end
|
64
|
+
|
65
|
+
def migration_config
|
66
|
+
@migration_config ||= {}
|
67
|
+
end
|
68
|
+
|
69
|
+
def migration_directory
|
70
|
+
@options[:migration_directory] || Rack::App::SeQueL::Migration::DEFAULT_DIRECTORY
|
71
|
+
end
|
72
|
+
|
73
|
+
def run_migrator(db, directory, config)
|
74
|
+
::Sequel::Migrator.run(db, directory, config)
|
75
|
+
rescue => ex
|
76
|
+
logger.error(ex.message)
|
77
|
+
@code = 1
|
78
|
+
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-app-sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
@@ -91,7 +91,12 @@ files:
|
|
91
91
|
- lib/rack/app/sequel/ext.rb
|
92
92
|
- lib/rack/app/sequel/migration.rb
|
93
93
|
- lib/rack/app/sequel/migration/cli.rb
|
94
|
+
- lib/rack/app/sequel/migration/cli/migrate.rb
|
95
|
+
- lib/rack/app/sequel/migration/cli/rollback.rb
|
96
|
+
- lib/rack/app/sequel/migration/cli/template.rb
|
97
|
+
- lib/rack/app/sequel/migration/cli/version.rb
|
94
98
|
- lib/rack/app/sequel/migration/template.rb
|
99
|
+
- lib/rack/app/sequel/runner.rb
|
95
100
|
- lib/rack/app/sequel/version.rb
|
96
101
|
- rack-app-sequel.gemspec
|
97
102
|
- script/database
|