pliny 0.30.1 → 0.31.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 +2 -1
- data/lib/pliny/db_support.rb +26 -8
- data/lib/pliny/tasks/db.rake +7 -0
- data/lib/pliny/version.rb +1 -1
- data/lib/template/Gemfile +1 -1
- data/spec/db_support_spec.rb +27 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03b6f9bac86953d6bef8858e6c4c1f6f94f06073fac8175b9572728ffed5a276
|
4
|
+
data.tar.gz: c20333f978e5f8e908b13f6eaf9d37a3dbdb0f10204c1db9a8b5f83b02fbac11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e851ccdd1fb0a3d548fa672d209829e9cd8ecf69023d1c7a2fb6ad0fb84ee1616d2d3b2a761d11ba9c13a989d2fb5176c31d3eb6acf9a02e20c6e7bc4b01386f
|
7
|
+
data.tar.gz: aefb3c02dc44ba282595bb9b2e85dc52e2891cb16ac6395693ab63bd79c603b7c68e9b93dea4c494c1b574e8be308b26a34e40040d4e71e0a74cb9a9f828a207
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Pliny
|
2
2
|
|
3
3
|
[![Gem version](http://img.shields.io/gem/v/pliny.svg)](https://rubygems.org/gems/pliny)
|
4
|
-
[![
|
4
|
+
[![Github Actions CI](https://github.com/interagent/pliny/actions/workflows/ruby.yml/badge.svg)](https://github.com/interagent/pliny/actions)
|
5
|
+
|
5
6
|
|
6
7
|
Pliny helps Ruby developers write and maintain excellent APIs.
|
7
8
|
|
data/lib/pliny/db_support.rb
CHANGED
@@ -46,25 +46,43 @@ module Pliny
|
|
46
46
|
db.run(%{CREATE DATABASE "#{name}"})
|
47
47
|
end
|
48
48
|
|
49
|
-
def migrate(target=nil)
|
50
|
-
Sequel::Migrator.apply(db,
|
49
|
+
def migrate(target = nil)
|
50
|
+
Sequel::Migrator.apply(db, MIGRATION_DIR, target)
|
51
|
+
end
|
52
|
+
|
53
|
+
def version
|
54
|
+
return 0 unless db.table_exists?(:schema_migrations)
|
55
|
+
|
56
|
+
current = db[:schema_migrations].order(Sequel.desc(:filename)).first
|
57
|
+
|
58
|
+
return 0 unless current
|
59
|
+
|
60
|
+
version = current[:filename].match(Sequel::Migrator::MIGRATION_FILE_PATTERN).captures.first
|
61
|
+
version ||= 0
|
62
|
+
Integer(version)
|
51
63
|
end
|
52
64
|
|
53
65
|
def rollback
|
54
|
-
|
55
|
-
return
|
66
|
+
current_version = version
|
67
|
+
return if current_version.zero?
|
68
|
+
|
69
|
+
migrations = Dir["#{MIGRATION_DIR}/*.rb"].map { |f| File.basename(f).to_i }.sort
|
56
70
|
|
57
|
-
|
58
|
-
|
59
|
-
index = migrations.index(current[:filename].to_i)
|
71
|
+
target = 0 # by default, rollback everything
|
72
|
+
index = migrations.index(current_version)
|
60
73
|
if index > 0
|
61
74
|
target = migrations[index - 1]
|
62
75
|
end
|
63
|
-
Sequel::Migrator.apply(db,
|
76
|
+
Sequel::Migrator.apply(db, MIGRATION_DIR, target)
|
64
77
|
end
|
65
78
|
|
66
79
|
def disconnect
|
67
80
|
@db.disconnect
|
68
81
|
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
MIGRATION_DIR = "./db/migrate".freeze
|
86
|
+
private_constant :MIGRATION_DIR
|
69
87
|
end
|
70
88
|
end
|
data/lib/pliny/tasks/db.rake
CHANGED
@@ -8,6 +8,13 @@ begin
|
|
8
8
|
require "pliny/db_support"
|
9
9
|
|
10
10
|
namespace :db do
|
11
|
+
desc "Get current schema version"
|
12
|
+
task :version do
|
13
|
+
Pliny::DbSupport.run(database_urls.first, $stdout) do |helper|
|
14
|
+
puts "Current version: #{helper.version}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
11
18
|
desc "Run database migrations"
|
12
19
|
task :migrate do
|
13
20
|
next if Dir["./db/migrate/*.rb"].empty?
|
data/lib/pliny/version.rb
CHANGED
data/lib/template/Gemfile
CHANGED
data/spec/db_support_spec.rb
CHANGED
@@ -2,9 +2,9 @@ require "spec_helper"
|
|
2
2
|
require "pliny/db_support"
|
3
3
|
|
4
4
|
describe Pliny::DbSupport do
|
5
|
+
subject(:support) { Pliny::DbSupport.new(url, logger) }
|
5
6
|
let(:url) { ENV["TEST_DATABASE_URL"] }
|
6
7
|
let(:logger) { Logger.new(StringIO.new) }
|
7
|
-
let(:support) { Pliny::DbSupport.new(url, logger) }
|
8
8
|
|
9
9
|
around do |example|
|
10
10
|
Dir.mktmpdir("plinytest-") do |dir|
|
@@ -88,4 +88,30 @@ describe Pliny::DbSupport do
|
|
88
88
|
support.rollback # should noop
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
describe "#version" do
|
93
|
+
it "is zero if the migrations table doesn't exist" do
|
94
|
+
assert_equal 0, support.version
|
95
|
+
end
|
96
|
+
|
97
|
+
context "with migrations table" do
|
98
|
+
before do
|
99
|
+
DB.create_table(:schema_migrations) do
|
100
|
+
text :filename
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "is zero if the migrations table is empty" do
|
105
|
+
assert_equal 0, support.version
|
106
|
+
end
|
107
|
+
|
108
|
+
it "is the highest timestamp from a filename in the migrations table" do
|
109
|
+
migrations = DB[:schema_migrations]
|
110
|
+
migrations.insert(filename: "1630551344_latest_change.rb")
|
111
|
+
migrations.insert(filename: "1524000760_earlier_change.rb")
|
112
|
+
|
113
|
+
assert_equal 1630551344, support.version
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
91
117
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pliny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.31.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur Leach
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-09-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|