sequel_tools 0.1.3 → 0.1.4
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 +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/sequel_tools.rb +2 -2
- data/lib/sequel_tools/actions/irb.rb +14 -0
- data/lib/sequel_tools/actions/migrate.rb +1 -1
- data/lib/sequel_tools/actions/new_migration.rb +1 -1
- data/lib/sequel_tools/actions/shell_postgres.rb +0 -1
- data/lib/sequel_tools/actions/status.rb +1 -1
- data/lib/sequel_tools/all_actions.rb +1 -0
- data/lib/sequel_tools/migration_utils.rb +4 -4
- data/lib/sequel_tools/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd0f583b78b874b3cfc1701a277ef182b184c66f
|
4
|
+
data.tar.gz: 980bc39cff7f7af9fcad83b4cd655d59aca0b3c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 912e0711195c5f895b40807d6013e899d6767f878438e2b4b173f910304e69928bf64da3c5c10db3d3ed12a9c768eb362fee42dc1b8726090278553fb86c4534
|
7
|
+
data.tar.gz: 55bfdf355d5f590e1d6ee16bd2096dce9c686ecbff614335928c96e08bb5477d1539542a1e0860919fc79ba59008c88b5d620f02522ed0d6b3aa1b9f2d1609c2
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -51,7 +51,7 @@ base_config = SequelTools.base_config(
|
|
51
51
|
dump_schema_on_migrate: false, # it's a good idea to enable it for the reference environment
|
52
52
|
pg_dump: 'pg_dump', # command used to run pg_dump
|
53
53
|
pg_dump: 'psql', # command used to run psql when calling rake db:shell if adapter is postgres
|
54
|
-
|
54
|
+
migrations_location: 'db/migrations',
|
55
55
|
schema_location: 'db/migrations/schema.sql',
|
56
56
|
seeds_location: 'db/seeds.rb',
|
57
57
|
maintenancedb: 'postgres' # for tasks such as creating the database
|
data/lib/sequel_tools.rb
CHANGED
@@ -8,7 +8,7 @@ module SequelTools
|
|
8
8
|
pg_dump: 'pg_dump', # command used to run pg_dump
|
9
9
|
psql: 'psql', # command used to run psql
|
10
10
|
maintenancedb: 'postgres', # DB to connect to for creating/dropping databases
|
11
|
-
|
11
|
+
migrations_location: 'db/migrations',
|
12
12
|
schema_location: 'db/migrations/schema.sql',
|
13
13
|
seeds_location: 'db/seeds.rb',
|
14
14
|
dbname: nil,
|
@@ -29,7 +29,7 @@ module SequelTools
|
|
29
29
|
REQUIRED_KEYS.each do |key|
|
30
30
|
raise MissingConfigError, "Expected value for #{key} config is missing" if config[key].nil?
|
31
31
|
end
|
32
|
-
[:
|
32
|
+
[:migrations_location, :schema_location, :seeds_location].each do |k|
|
33
33
|
config[k] = File.expand_path config[k], config[:project_root]
|
34
34
|
end
|
35
35
|
config
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
require_relative '../actions_manager'
|
4
|
+
|
5
|
+
class SequelTools::ActionsManager
|
6
|
+
# TODO: this action is not currently tested automatically as it's not critical and not
|
7
|
+
# trivial to write a test for
|
8
|
+
description = "Opens an IRB session started as 'sequel uri_to_database' (DB is available to irb)"
|
9
|
+
Action.register :irb, description do |args, context|
|
10
|
+
config = context[:config]
|
11
|
+
uri = context[:uri_builder][config]
|
12
|
+
exec "bundle exec sequel #{uri}"
|
13
|
+
end
|
14
|
+
end
|
@@ -12,7 +12,7 @@ class SequelTools::ActionsManager
|
|
12
12
|
Sequel.extension :migration unless Sequel.respond_to? :migration
|
13
13
|
options = {}
|
14
14
|
options[:target] = args[:version].to_i if args[:version]
|
15
|
-
Sequel::Migrator.run db, config[:
|
15
|
+
Sequel::Migrator.run db, config[:migrations_location], options
|
16
16
|
Action[:schema_dump].run({}, context) if config[:dump_schema_on_migrate]
|
17
17
|
end
|
18
18
|
end
|
@@ -7,7 +7,7 @@ class SequelTools::ActionsManager
|
|
7
7
|
Action.register :new_migration, desc, arg_names: [ :name ] do |args, context|
|
8
8
|
(puts 'Migration name is missing - aborting'; exit 1) unless name = args[:name]
|
9
9
|
require 'time'
|
10
|
-
migrations_path = context[:config][:
|
10
|
+
migrations_path = context[:config][:migrations_location]
|
11
11
|
filename = "#{migrations_path}/#{Time.now.strftime '%Y%m%d%H%M%S'}_#{name}.rb"
|
12
12
|
File.write filename, <<~MIGRATIONS_TEMPLATE_END
|
13
13
|
# documentation available at http://sequel.jeremyevans.net/rdoc/files/doc/migration_rdoc.html
|
@@ -8,7 +8,7 @@ class SequelTools::ActionsManager
|
|
8
8
|
description = 'Show migrations status (applied and missing in migrations path vs unapplied)'
|
9
9
|
Action.register :status, description do |args, context|
|
10
10
|
unapplied, files_missing = MigrationUtils.migrations_differences context
|
11
|
-
path = context[:config][:
|
11
|
+
path = context[:config][:migrations_location]
|
12
12
|
unless files_missing.empty?
|
13
13
|
puts "The following migrations were applied to the database but can't be found in #{path}:"
|
14
14
|
puts files_missing.map{|fn| " - #{fn}" }.join("\n")
|
@@ -22,8 +22,8 @@ class MigrationUtils
|
|
22
22
|
options = { allow_missing_migration_files: true }
|
23
23
|
options[:target] = 0 if direction == :down
|
24
24
|
config = context[:config]
|
25
|
-
Sequel::Migrator.migrator_class(config[:
|
26
|
-
new(context[:db], config[:
|
25
|
+
Sequel::Migrator.migrator_class(config[:migrations_location]).
|
26
|
+
new(context[:db], config[:migrations_location], options)
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.current_version(context)
|
@@ -32,7 +32,7 @@ class MigrationUtils
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.last_found_migration(context)
|
35
|
-
migrations_path = context[:config][:
|
35
|
+
migrations_path = context[:config][:migrations_location]
|
36
36
|
migrator = find_migrator(context)
|
37
37
|
migrator.ds.order(Sequel.desc(migrator.column)).select_map(migrator.column).find do |fn|
|
38
38
|
File.exist?("#{migrations_path}/#{fn}")
|
@@ -41,7 +41,7 @@ class MigrationUtils
|
|
41
41
|
|
42
42
|
def self.migrations_differences(context)
|
43
43
|
config = context[:config]
|
44
|
-
migrations_path = config[:
|
44
|
+
migrations_path = config[:migrations_location]
|
45
45
|
existing = Dir["#{migrations_path}/*.rb"].map{|fn| File.basename fn }.sort
|
46
46
|
migrator = find_migrator context
|
47
47
|
migrated = migrator.ds.select_order_map(migrator.column)
|
data/lib/sequel_tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Rosenfeld Rosas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/sequel_tools/actions/create_db.rb
|
111
111
|
- lib/sequel_tools/actions/down.rb
|
112
112
|
- lib/sequel_tools/actions/drop_db.rb
|
113
|
+
- lib/sequel_tools/actions/irb.rb
|
113
114
|
- lib/sequel_tools/actions/migrate.rb
|
114
115
|
- lib/sequel_tools/actions/new_migration.rb
|
115
116
|
- lib/sequel_tools/actions/redo.rb
|