sequel-data-migrate 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16896608fde97a13bbe21af4275a06a3229f57c215719b2a569a9eb974ebdf89
4
- data.tar.gz: 453e7f4a1afd9ed0bbd9ed3398858b366f81285b57ee5dd3e6decd552c2fd852
3
+ metadata.gz: 7a03e567fda7ed849e9a70868d7395a1d9d4a8584b3027c4e9f21ad0ad73ef2f
4
+ data.tar.gz: 852e56344cc564be33d1028b504b735c42195d09a12e982bd148ce7435dd80c7
5
5
  SHA512:
6
- metadata.gz: eac60cb9d571d250198ed6476b4a049af93652f5a00fc5b84ab02e534d4e0a78f60dad9b703d5d3dbf02c5e606d53400193c5b65460d83573a4dac81ebca5f54
7
- data.tar.gz: e420debfc7d44f438ee5a5aa7a2447a952ebc02da7dadb2e1f5960d2cae103be93c68ba4d20b441319b5a2f3fbc970ccae5890dc647c2b5eba5596be5908f94c
6
+ metadata.gz: 6a7231580196995771534f090b14e2c92a941465a60779716e125606719c682fb3cf1a8bb23a65c6f84e1842a372a5816db3be9c1e61caea77f166b75f691ac0
7
+ data.tar.gz: bc2017007f8fa13551e49674d1be6f6f2120c8380baec8f1d961ef6e2d57b464566f76a8ed9a4f027c664ae54c3780becd433b13e8cee4ea2bfd46dab5cd0ac8
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
- ## [Unreleased]
1
+ ## [0.1.2] - 2024-01-08
2
+
3
+ - Avoid leaking DB connections
4
+
5
+ ## [0.1.1] - 2023-09-01
6
+
7
+ - Update gemspec to avoid `git ls-files`
8
+ - Support dry-configuration version 0.10.x - 0.12.x
2
9
 
3
10
  ## [0.1.0] - 2023-04-11
4
11
 
data/README.md CHANGED
@@ -38,8 +38,8 @@ task 'data:migrate' => :environment
38
38
  task 'data:rollback' => :environment
39
39
  ```
40
40
 
41
- Now you can migrate using `rake db:migrate` and rollback using `rake
42
- db:rollback`.
41
+ Now you can migrate using `rake data:migrate` and rollback using `rake
42
+ data:rollback`.
43
43
 
44
44
  To create new migration file, you can use `data:create_migration` rake task:
45
45
 
@@ -1,4 +1,6 @@
1
- require 'fileutils'
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
2
4
 
3
5
  module SequelData
4
6
  module Migrate
@@ -15,39 +15,41 @@ module SequelData
15
15
  end
16
16
 
17
17
  def migrate
18
- db = connect_database
19
- dataset = ensure_table_exists(db)
20
-
21
- already_migrated = dataset.select_map(column).to_set
22
- migration_files = fetch_migration_files.reject { |file| already_migrated.include?(File.basename(file)) }.sort
23
- migrations = fetch_migrations(migration_files)
24
-
25
- migrations.zip(migration_files).each do |migration, file|
26
- db.log_info("Begin applying migration file #{file}")
27
- migration.new.up
28
- set_migration_version(db, file)
29
- db.log_info("Finished applying migration version #{file}")
18
+ connect_database do |db|
19
+ dataset = ensure_table_exists(db)
20
+
21
+ already_migrated = dataset.select_map(column).to_set
22
+ migration_files = fetch_migration_files.reject { |file| already_migrated.include?(File.basename(file)) }.sort
23
+ migrations = fetch_migrations(migration_files)
24
+
25
+ migrations.zip(migration_files).each do |migration, file|
26
+ db.log_info("Begin applying migration file #{file}")
27
+ migration.new.up
28
+ set_migration_version(db, file)
29
+ db.log_info("Finished applying migration version #{file}")
30
+ end
30
31
  end
31
32
  end
32
33
 
33
34
  def rollback(step = 1)
34
- db = connect_database
35
- dataset = ensure_table_exists(db)
36
-
37
- already_migrated = dataset.select_map(column).to_set
38
- migration_files = fetch_migration_files.select do |file|
39
- already_migrated.include?(File.basename(file))
40
- end.sort.reverse!
41
- migrations = fetch_migrations(migration_files)
42
-
43
- migrations.zip(migration_files).each do |migration, file|
44
- step -= 1
45
- break if step.negative?
46
-
47
- db.log_info("Begin rolling back migration file #{file}")
48
- migration.new.down
49
- remove_migration_version(db, file)
50
- db.log_info("Finished rolling back migration version #{file}")
35
+ connect_database do |db|
36
+ dataset = ensure_table_exists(db)
37
+
38
+ already_migrated = dataset.select_map(column).to_set
39
+ migration_files = fetch_migration_files.select do |file|
40
+ already_migrated.include?(File.basename(file))
41
+ end.sort.reverse!
42
+ migrations = fetch_migrations(migration_files)
43
+
44
+ migrations.zip(migration_files).each do |migration, file|
45
+ step -= 1
46
+ break if step.negative?
47
+
48
+ db.log_info("Begin rolling back migration file #{file}")
49
+ migration.new.down
50
+ remove_migration_version(db, file)
51
+ db.log_info("Finished rolling back migration version #{file}")
52
+ end
51
53
  end
52
54
  end
53
55
 
@@ -63,10 +65,10 @@ module SequelData
63
65
  :data_migrations
64
66
  end
65
67
 
66
- def connect_database
68
+ def connect_database(&block)
67
69
  raise ConfigurationError, "db_configuration is not set" if config.db_configuration.host.nil?
68
70
 
69
- Sequel.connect(config.db_configuration.host)
71
+ Sequel.connect(config.db_configuration.host, &block)
70
72
  end
71
73
 
72
74
  def ensure_table_exists(db)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SequelData
4
4
  module Migrate
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry-configurable"
4
+ require "dry/configurable/version"
4
5
  require "sequel_data/migrate/version"
5
6
  require "sequel_data/migrate/errors"
6
7
  require "sequel_data/migrate/migrator"
@@ -13,7 +14,12 @@ module SequelData
13
14
  setting :db_configuration do
14
15
  setting :host
15
16
  end
16
- setting :migration_path, default: "db/data"
17
+
18
+ if Dry::Configurable::VERSION >= "0.13.0"
19
+ setting :migration_path, default: "db/data"
20
+ else
21
+ setting :migration_path, "db/data"
22
+ end
17
23
 
18
24
  def self.migrate
19
25
  Migrator.new(config).migrate
@@ -54,7 +54,7 @@ module SequelData
54
54
  attr_reader config: untyped
55
55
  def column: -> :version
56
56
  def table: -> :data_migrations
57
- def connect_database: -> untyped
57
+ def connect_database: () { (untyped db) -> void } -> untyped
58
58
  def ensure_table_exists: (untyped db) -> untyped
59
59
  def fetch_migration_files: -> Array[String]
60
60
  def load_migration_file: (String file) -> untyped
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-data-migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hieu Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-11 00:00:00.000000000 Z
11
+ date: 2024-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.13.0
19
+ version: 0.10.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.13.0
26
+ version: 0.10.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sequel
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,14 +45,9 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - ".rspec"
49
- - ".rubocop.yml"
50
- - ".ruby-version"
51
48
  - CHANGELOG.md
52
- - Gemfile
53
49
  - LICENSE.txt
54
50
  - README.md
55
- - Rakefile
56
51
  - lib/sequel_data/migrate.rb
57
52
  - lib/sequel_data/migrate/errors.rb
58
53
  - lib/sequel_data/migrate/generator.rb
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,28 +0,0 @@
1
- require:
2
- - rubocop-rspec
3
-
4
- AllCops:
5
- TargetRubyVersion: 2.7
6
- NewCops: enable
7
-
8
- Layout/LineLength:
9
- Max: 120
10
-
11
- Metrics/AbcSize:
12
- Max: 50
13
- Metrics/MethodLength:
14
- Max: 20
15
-
16
- RSpec/ExampleLength:
17
- Max: 20
18
- RSpec/MultipleExpectations:
19
- Enabled: false
20
-
21
- Style/Documentation:
22
- Enabled: false
23
- Style/StringLiterals:
24
- Enabled: true
25
- EnforcedStyle: double_quotes
26
- Style/StringLiteralsInInterpolation:
27
- Enabled: true
28
- EnforcedStyle: double_quotes
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.1.2
data/Gemfile DELETED
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in sequel-data-migrate.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
9
- gem "rbs"
10
- gem "sqlite3"
11
-
12
- gem "rspec"
13
-
14
- gem "rubocop"
15
- gem "rubocop-rspec"
16
-
17
- gem "byebug"
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]