sequel-rake 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/Rakefile +0 -2
- data/lib/sequel/rake/tasks.rake +63 -0
- data/lib/sequel/rake.rb +28 -85
- metadata +4 -3
- data/lib/sequel/database.yml +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c87cab3732a1ecd2a079afc7428096a97d45d1a
|
4
|
+
data.tar.gz: ab876b7698e792d3b6063806a14541768fe3ed32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33f38bf1623a696053ce84e891ad806902da2e4b8adfd292ad14f4d1de3b77ec65c42b128553e9ed593189a89d7fdae8641115ff48e83331ca3675a92c879146
|
7
|
+
data.tar.gz: 77ca6b4608f1f6ed48c769f5849a65ae24ff993ec85794fab7e1747b5d15f8a52e665db17ae4447746002c20b879bc7373b81f6766d5181c879739d36c7a1c19
|
data/README.md
CHANGED
@@ -32,9 +32,10 @@ require 'sequel/rake'
|
|
32
32
|
```
|
33
33
|
$ bundle exec rake ...
|
34
34
|
|
35
|
-
sequel:generate[name] # Generate a new migration file `sequel:generate[create_books]`
|
36
35
|
sequel:init # Creates a database.yml file
|
36
|
+
sequel:generate[name] # Generate a new migration file `sequel:generate[create_books]`
|
37
37
|
sequel:migrate[version] # Migrate the database (you can specify the version with `db:migrate[N]`)
|
38
|
+
sequel:rollback[step] # Rollback the database N steps (you can specify the version with `db:rollback[N]`)
|
38
39
|
sequel:remigrate # Undo all migrations and migrate again
|
39
40
|
```
|
40
41
|
|
@@ -42,6 +43,7 @@ sequel:remigrate # Undo all migrations and migrate again
|
|
42
43
|
|
43
44
|
* Rollback to previous version
|
44
45
|
* Write some tests
|
46
|
+
* Seeds
|
45
47
|
|
46
48
|
## Contributing
|
47
49
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
namespace :sequel do
|
2
|
+
require "sequel"
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
desc "Creates the migrations directory"
|
6
|
+
task :init do
|
7
|
+
FileUtils::mkdir_p migrations
|
8
|
+
puts "generated: #{migrations}"
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Generate a new migration file `sequel:generate[create_books]`"
|
12
|
+
task :generate, :name do |_, args|
|
13
|
+
name = args[:name]
|
14
|
+
abort("Missing migration file name") if name.nil?
|
15
|
+
|
16
|
+
content = "# frozen_string_literal: true\n\nSequel.migration do\n change do\n \n end\nend\n"
|
17
|
+
timestamp = Time.now.to_i
|
18
|
+
filename = File.join(migrations, "#{timestamp}_#{name}.rb")
|
19
|
+
File.write(filename, content)
|
20
|
+
puts "Generated: #{filename}"
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Migrate the database (you can specify the version with `db:migrate[N]`)"
|
24
|
+
task :migrate, [:version] do |task, args|
|
25
|
+
version = args[:version] ? Integer(args[:version]) : nil
|
26
|
+
migrate(version)
|
27
|
+
puts "Migration complete"
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Rollback the database N steps (you can specify the version with `db:rollback[N]`"
|
31
|
+
task :rollback, [:step] do |task, args|
|
32
|
+
step = args[:step] ? Integer(args[:step]) : 1
|
33
|
+
version = 0
|
34
|
+
|
35
|
+
if row = connection[:schema_migrations].order(Sequel.desc(:filename)).offset(step).first
|
36
|
+
version = Integer(row[:filename].match(/([\d]+)/)[0])
|
37
|
+
end
|
38
|
+
|
39
|
+
migrate(version)
|
40
|
+
puts "Rollback complete"
|
41
|
+
puts "Rolled back to version: #{version}"
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Undo all migrations and migrate again"
|
45
|
+
task :remigrate do
|
46
|
+
migrate(0)
|
47
|
+
migrate
|
48
|
+
puts "Remigration complete"
|
49
|
+
end
|
50
|
+
|
51
|
+
def migrate(version = nil)
|
52
|
+
Sequel.extension :migration
|
53
|
+
Sequel::Migrator.apply(connection, migrations, version)
|
54
|
+
end
|
55
|
+
|
56
|
+
def connection
|
57
|
+
@connection ||= Sequel.connect(Sequel::Rake.get(:connection))
|
58
|
+
end
|
59
|
+
|
60
|
+
def migrations
|
61
|
+
Sequel::Rake.get(:migrations)
|
62
|
+
end
|
63
|
+
end
|
data/lib/sequel/rake.rb
CHANGED
@@ -1,97 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Sequel
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
# Sequel::Rake.configure do
|
7
|
+
# set :connection, ENV["DATABASE_URL"]
|
8
|
+
# set :migrations, "#{__dir__}/lib/db/migrations"
|
9
|
+
# end
|
10
|
+
#
|
4
11
|
module Rake
|
5
12
|
# Current version number.
|
6
|
-
VERSION = '0.0
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
desc 'Creates a database.yml file'
|
16
|
-
task :init do
|
17
|
-
skeleton = "#{__dir__}/database.yml"
|
18
|
-
|
19
|
-
if File.directory?(path('config'))
|
20
|
-
FileUtils.cp(skeleton, path('config/database.yml'))
|
21
|
-
else
|
22
|
-
FileUtils.cp(skeleton, path('database.yml'))
|
23
|
-
end
|
24
|
-
|
25
|
-
FileUtils::mkdir_p path('db/migrations')
|
26
|
-
end
|
27
|
-
|
28
|
-
desc 'Generate a new migration file `sequel:generate[create_books]`'
|
29
|
-
task :generate, :name do |_, args|
|
30
|
-
name = args[:name]
|
31
|
-
abort('Missing migration file name') if name.nil?
|
32
|
-
|
33
|
-
content = "# frozen_string_literal: true\n\nSequel.migration do\n change do\n \n end\nend\n"
|
34
|
-
timestamp = Time.now.to_i
|
35
|
-
filename = File.join(config[env]['migrations'], "#{timestamp}_#{name}.rb")
|
36
|
-
|
37
|
-
File.write(filename, content)
|
38
|
-
end
|
39
|
-
|
40
|
-
desc 'Migrate the database (you can specify the version with `db:migrate[N]`)'
|
41
|
-
task :migrate, [:version] do |task, args|
|
42
|
-
version = args[:version] ? Integer(args[:version]) : nil
|
43
|
-
migrate(version)
|
44
|
-
end
|
45
|
-
|
46
|
-
desc 'Undo all migrations and migrate again'
|
47
|
-
task :remigrate do
|
48
|
-
migrate(0)
|
49
|
-
migrate
|
50
|
-
end
|
51
|
-
|
52
|
-
def migrate(version = nil)
|
53
|
-
databases.each do |db|
|
54
|
-
conn, opts = db
|
55
|
-
Sequel.extension :migration
|
56
|
-
Sequel::Migrator.apply(conn, opts['migrations'], version)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def databases
|
61
|
-
envs = []
|
62
|
-
if env == 'production' || env == 'staging'
|
63
|
-
envs << env
|
64
|
-
else
|
65
|
-
envs.concat(['development', 'test'])
|
66
|
-
end
|
67
|
-
envs.map { |e| [Sequel.connect(config[e]), config[env]] }
|
68
|
-
end
|
69
|
-
|
70
|
-
def path(path)
|
71
|
-
"#{Dir.pwd}/#{path}"
|
72
|
-
end
|
73
|
-
|
74
|
-
def connection
|
75
|
-
@connection ||= Sequel.connect(config)
|
76
|
-
end
|
13
|
+
VERSION = '0.1.0'
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def configuration
|
17
|
+
@configuration ||= {
|
18
|
+
connection: ENV["DATABASE_URL"],
|
19
|
+
migrations: "db/migrations"
|
20
|
+
}
|
21
|
+
end
|
77
22
|
|
78
|
-
|
79
|
-
|
80
|
-
|
23
|
+
def configure(&block)
|
24
|
+
instance_eval(&block)
|
25
|
+
end
|
81
26
|
|
82
|
-
|
83
|
-
|
27
|
+
def set(key, value)
|
28
|
+
configuration[key] = value
|
29
|
+
end
|
84
30
|
|
85
|
-
|
86
|
-
|
87
|
-
end
|
31
|
+
def get(key)
|
32
|
+
configuration.fetch(key)
|
88
33
|
end
|
89
34
|
|
90
|
-
|
35
|
+
def load!
|
36
|
+
load "#{__dir__}/rake/tasks.rake"
|
37
|
+
end
|
91
38
|
end
|
92
39
|
end
|
93
|
-
|
94
|
-
def env
|
95
|
-
ENV['RACK_ENV'] || 'development'
|
96
|
-
end
|
97
|
-
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-rake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Sandelius
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -135,8 +135,8 @@ files:
|
|
135
135
|
- LICENSE.txt
|
136
136
|
- README.md
|
137
137
|
- Rakefile
|
138
|
-
- lib/sequel/database.yml
|
139
138
|
- lib/sequel/rake.rb
|
139
|
+
- lib/sequel/rake/tasks.rake
|
140
140
|
- sequel-rake.gemspec
|
141
141
|
- test/test_helper.rb
|
142
142
|
- test/unit/rake_test.rb
|
@@ -167,3 +167,4 @@ summary: Rake tasks for the Sequel gem.
|
|
167
167
|
test_files:
|
168
168
|
- test/test_helper.rb
|
169
169
|
- test/unit/rake_test.rb
|
170
|
+
has_rdoc:
|
data/lib/sequel/database.yml
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
defaults: &defaults
|
2
|
-
migrations: db/migrations
|
3
|
-
adapter: postgres
|
4
|
-
max_connections: 5
|
5
|
-
host: localhost
|
6
|
-
user: postgres
|
7
|
-
|
8
|
-
development:
|
9
|
-
<<: *defaults
|
10
|
-
password:
|
11
|
-
database: app_development
|
12
|
-
|
13
|
-
test:
|
14
|
-
<<: *defaults
|
15
|
-
password:
|
16
|
-
database: app_test
|
17
|
-
|
18
|
-
staging:
|
19
|
-
<<: *defaults
|
20
|
-
password:
|
21
|
-
database: app_staging
|
22
|
-
|
23
|
-
production:
|
24
|
-
<<: *defaults
|
25
|
-
password:
|
26
|
-
database: app
|