umbrellio-sequel-plugins 0.12.0.159 → 0.12.0.169

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: 142f01fd5727cf3e7e9e9f656679bc17e7aadd5935a11e0602a6dfa2aa9a37c9
4
- data.tar.gz: c3bf80f72c94ea9646fa8429de4e6af18a98757eb6c83f9928a32655f52c4321
3
+ metadata.gz: 6a1f6f4eb4543668bd64fc9aaa0f666587d450eeb048bc3f20cb04d17d3cdfad
4
+ data.tar.gz: e2dd754b79b6a68d1eeddd8a282ec654db075c8f623793e8b454ad965358daba
5
5
  SHA512:
6
- metadata.gz: 605ef2b5494a4918504a2f6c172b93f2691d6546949b26f0cad018b30aa1eaba470ee5b1b2434c58ddf545236c0d357bf66ecbe4be5e80ce9d6e7461f39b99e5
7
- data.tar.gz: 5a68bb15ddcc7a6526cbb208b703bd8de36b68ac0c4111e4f3d7a647c7cc5c74572900191080d8c97a7fc74e947abf9ac1ee3e512b12eb9664dc43734f4f2919
6
+ metadata.gz: 22bfdde950888dff4767f1ed733fae0806f5336b00dc065f21be0917d218a02fe7a202ce72dcdea1f46863b06b9067c1aefa675fefedf9aff98270812b78ccda
7
+ data.tar.gz: 83fd34102711a4bb19bb67a7c912ae11f49cdbc346343fb0e98ae96fbc201476c68037c40699d0f53089208d0f5227221e96c5a046118a72a126a229c6893eb0
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :sequel do
4
+ desc "Archive migrations source code"
5
+ task archive_migrations: :environment do
6
+ DB.create_table?(:schema_migrations_sources) do
7
+ column :version, "numeric", primary_key: true
8
+ column :filename, "text", null: false
9
+ column :source, "text", null: false
10
+ end
11
+
12
+ migrations = Rails.root.glob("db/migrate/*.rb").map do |file|
13
+ filename = file.basename.to_s
14
+ { version: filename.to_i, filename: filename, source: file.read }
15
+ end
16
+
17
+ conflict_options = {
18
+ target: :version,
19
+ update: { source: Sequel[:excluded][:source] },
20
+ }
21
+
22
+ DB[:schema_migrations_sources].insert_conflict(**conflict_options).multi_insert(migrations)
23
+ end
24
+ end
@@ -7,20 +7,27 @@ namespace :sequel do
7
7
  task rollback_archived_migrations: :environment do
8
8
  DB.log_info("Finding applied migrations not present in current release...")
9
9
 
10
- archive_path = Pathname.new(ENV.fetch("ARCHIVE_PATH")).expand_path.join("db/migrate")
11
- migrator = Sequel::TimestampMigrator.new(DB, archive_path, allow_missing_migration_files: true)
10
+ Dir.mktmpdir do |tmpdir|
11
+ DB[:schema_migrations_sources].each do |migration|
12
+ path = File.join(tmpdir, migration.fetch(:filename))
13
+ File.write(path, migration.fetch(:source))
14
+ end
15
+
16
+ migrator = Sequel::TimestampMigrator.new(DB, tmpdir, allow_missing_migration_files: true)
12
17
 
13
- applied_migrations = migrator.applied_migrations.map(&:to_i)
14
- filesystem_migrations = Rails.root.glob("db/migrate/*.rb").map { |x| File.basename(x).to_i }
15
- missing_migrations = applied_migrations - filesystem_migrations
18
+ applied_migrations = migrator.applied_migrations.map(&:to_i)
19
+ filesystem_migrations = Rails.root.glob("db/migrate/*.rb").map { |x| File.basename(x).to_i }
20
+ missing_migrations = applied_migrations - filesystem_migrations
16
21
 
17
- if missing_migrations.any?
18
- missing_migrations.each do |migration|
19
- DB.log_info("Rolling back migration #{migration}...")
20
- migrator.undo(migration)
22
+ if missing_migrations.any?
23
+ missing_migrations.each do |migration|
24
+ DB.log_info("Rolling back migration #{migration}...")
25
+ migrator.undo(migration)
26
+ end
27
+ else
28
+ DB.log_info("No migrations found")
29
+ "No migrations found"
21
30
  end
22
- else
23
- DB.log_info("No migrations found")
24
31
  end
25
32
  end
26
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umbrellio-sequel-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0.159
4
+ version: 0.12.0.169
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Umbrellio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-11 00:00:00.000000000 Z
11
+ date: 2023-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -75,6 +75,7 @@ files:
75
75
  - lib/sequel/plugins/upsert.rb
76
76
  - lib/sequel/plugins/with_lock.rb
77
77
  - lib/sequel/timestamp_migrator_undo_extension.rb
78
+ - lib/tasks/sequel/archive_migrations.rake
78
79
  - lib/tasks/sequel/rollback_archived_migrations.rake
79
80
  - lib/tasks/sequel/rollback_missing_migrations.rake
80
81
  - lib/tasks/sequel/undo.rake