pliny 0.30.1 → 0.31.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 594ffc14e101ac813df431ff24c41370089114f5d5505b5a0ff72b0f6b2bc3bf
4
- data.tar.gz: 1567a181f563ab92e1e7cef94cfcc38f60cd4f742b16a16580a1d2705396712b
3
+ metadata.gz: 03b6f9bac86953d6bef8858e6c4c1f6f94f06073fac8175b9572728ffed5a276
4
+ data.tar.gz: c20333f978e5f8e908b13f6eaf9d37a3dbdb0f10204c1db9a8b5f83b02fbac11
5
5
  SHA512:
6
- metadata.gz: bdae87227f343e45275c2cc40afce4ed16d5610dc2c9cbc824ac96ecbd4a88747d5599abacec72c9fdfa8ee5d217aab426cb5b42dcfe1931b8a9e98bf38f13d8
7
- data.tar.gz: 0b4f1418cdfa8adb477063400cbbd16398cf44b2615dee460bb23f0e839820567b1bf6c7bfa590ed37ae32490336b022e1df53e03161b893e331d44b4e23b09c
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
- [![Build Status](https://travis-ci.org/interagent/pliny.svg?branch=master)](https://travis-ci.org/interagent/pliny)
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
 
@@ -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, "./db/migrate", target)
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
- return unless db.tables.include?(:schema_migrations)
55
- return unless current = db[:schema_migrations].order(Sequel.desc(:filename)).first
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
- migrations = Dir["./db/migrate/*.rb"].map { |f| File.basename(f).to_i }.sort
58
- target = 0 # by default, rollback everything
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, "./db/migrate", target)
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.30.1"
2
+ VERSION = "0.31.0"
3
3
  end
data/lib/template/Gemfile CHANGED
@@ -4,7 +4,7 @@ ruby "2.4.0"
4
4
  gem "multi_json"
5
5
  gem "oj"
6
6
  gem "pg"
7
- gem "pliny", "~> 0.30"
7
+ gem "pliny", "~> 0.31"
8
8
  gem "pry"
9
9
  gem "puma", "~> 3"
10
10
  gem "rack-ssl"
@@ -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.30.1
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-06-17 00:00:00.000000000 Z
12
+ date: 2021-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport