umbrellio-sequel-plugins 0.16.0.239 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +0 -3
- data/.gitignore +0 -1
- data/Gemfile +10 -10
- data/Gemfile.lock +153 -0
- data/README.md +124 -0
- data/lib/clickhouse/migrator.rb +32 -0
- data/lib/sequel/extensions/fibered_connection_pool.rb +3 -9
- data/lib/tasks/clickhouse.rake +59 -0
- data/lib/tasks/sequel/archive_migrations.rake +8 -4
- data/lib/tasks/sequel/rollback_archived_migrations.rake +15 -4
- data/lib/tasks/sequel/rollback_missing_migrations.rake +9 -2
- data/umbrellio-sequel-plugins.gemspec +1 -7
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7572a3f551bf5409ea0cca6442366ec84ae4cf7776e379f3e020f099fe41f4c
|
4
|
+
data.tar.gz: f3dc5382d920669c883e7ae4d77e340f97df35c3d9bffbac3b258b03653b9744
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0381a1a25eae8e70624c830a3c09554efe042efb97c8218ef5137a7fc04056ebac42d5f976eb425c6aee9c5ccf711a945811213833e0e7acabcb608315e31f9
|
7
|
+
data.tar.gz: 640655214164e3f23290c4b3d2f60df248638ecdadb98687dc68f85d49276af31e768bbde3c1dfdbf11b29f8589427ade0a44ae39c4d6d0a461427dbf4ea544b
|
data/.github/workflows/ci.yml
CHANGED
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -4,13 +4,13 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
gem "async"
|
8
|
-
gem "money"
|
9
|
-
gem "pg"
|
10
|
-
gem "pry"
|
11
|
-
gem "rake"
|
12
|
-
gem "rspec"
|
13
|
-
gem "rubocop-config-umbrellio"
|
14
|
-
gem "simplecov"
|
15
|
-
gem "simplecov-lcov"
|
16
|
-
gem "symbiont-ruby"
|
7
|
+
gem "async"
|
8
|
+
gem "money"
|
9
|
+
gem "pg"
|
10
|
+
gem "pry"
|
11
|
+
gem "rake"
|
12
|
+
gem "rspec"
|
13
|
+
gem "rubocop-config-umbrellio"
|
14
|
+
gem "simplecov"
|
15
|
+
gem "simplecov-lcov"
|
16
|
+
gem "symbiont-ruby"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
umbrellio-sequel-plugins (0.17.0)
|
5
|
+
sequel
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (7.1.4)
|
11
|
+
base64
|
12
|
+
bigdecimal
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
connection_pool (>= 2.2.5)
|
15
|
+
drb
|
16
|
+
i18n (>= 1.6, < 2)
|
17
|
+
minitest (>= 5.1)
|
18
|
+
mutex_m
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
ast (2.4.2)
|
21
|
+
async (1.32.1)
|
22
|
+
console (~> 1.10)
|
23
|
+
nio4r (~> 2.3)
|
24
|
+
timers (~> 4.1)
|
25
|
+
base64 (0.2.0)
|
26
|
+
bigdecimal (3.1.8)
|
27
|
+
coderay (1.1.3)
|
28
|
+
concurrent-ruby (1.3.4)
|
29
|
+
connection_pool (2.4.1)
|
30
|
+
console (1.24.0)
|
31
|
+
fiber-annotation
|
32
|
+
fiber-local
|
33
|
+
json
|
34
|
+
diff-lcs (1.5.1)
|
35
|
+
docile (1.4.1)
|
36
|
+
drb (2.2.1)
|
37
|
+
fiber-annotation (0.2.0)
|
38
|
+
fiber-local (1.0.0)
|
39
|
+
i18n (1.14.5)
|
40
|
+
concurrent-ruby (~> 1.0)
|
41
|
+
json (2.7.2)
|
42
|
+
language_server-protocol (3.17.0.3)
|
43
|
+
method_source (1.1.0)
|
44
|
+
minitest (5.25.1)
|
45
|
+
money (6.19.0)
|
46
|
+
i18n (>= 0.6.4, <= 2)
|
47
|
+
mutex_m (0.2.0)
|
48
|
+
nio4r (2.7.3)
|
49
|
+
parallel (1.26.3)
|
50
|
+
parser (3.3.5.0)
|
51
|
+
ast (~> 2.4.1)
|
52
|
+
racc
|
53
|
+
pg (1.5.8)
|
54
|
+
pry (0.14.2)
|
55
|
+
coderay (~> 1.1)
|
56
|
+
method_source (~> 1.0)
|
57
|
+
racc (1.8.1)
|
58
|
+
rack (3.1.7)
|
59
|
+
rainbow (3.1.1)
|
60
|
+
rake (13.2.1)
|
61
|
+
regexp_parser (2.9.2)
|
62
|
+
rexml (3.3.7)
|
63
|
+
rspec (3.13.0)
|
64
|
+
rspec-core (~> 3.13.0)
|
65
|
+
rspec-expectations (~> 3.13.0)
|
66
|
+
rspec-mocks (~> 3.13.0)
|
67
|
+
rspec-core (3.13.1)
|
68
|
+
rspec-support (~> 3.13.0)
|
69
|
+
rspec-expectations (3.13.3)
|
70
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
+
rspec-support (~> 3.13.0)
|
72
|
+
rspec-mocks (3.13.1)
|
73
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
74
|
+
rspec-support (~> 3.13.0)
|
75
|
+
rspec-support (3.13.1)
|
76
|
+
rubocop (1.63.5)
|
77
|
+
json (~> 2.3)
|
78
|
+
language_server-protocol (>= 3.17.0)
|
79
|
+
parallel (~> 1.10)
|
80
|
+
parser (>= 3.3.0.2)
|
81
|
+
rainbow (>= 2.2.2, < 4.0)
|
82
|
+
regexp_parser (>= 1.8, < 3.0)
|
83
|
+
rexml (>= 3.2.5, < 4.0)
|
84
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
85
|
+
ruby-progressbar (~> 1.7)
|
86
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
87
|
+
rubocop-ast (1.32.3)
|
88
|
+
parser (>= 3.3.1.0)
|
89
|
+
rubocop-capybara (2.21.0)
|
90
|
+
rubocop (~> 1.41)
|
91
|
+
rubocop-config-umbrellio (1.63.0.93)
|
92
|
+
rubocop (~> 1.63.0)
|
93
|
+
rubocop-performance (~> 1.21.0)
|
94
|
+
rubocop-rails (~> 2.24.0)
|
95
|
+
rubocop-rake (~> 0.6.0)
|
96
|
+
rubocop-rspec (~> 2.29.0)
|
97
|
+
rubocop-sequel (~> 0.3.3)
|
98
|
+
rubocop-factory_bot (2.26.1)
|
99
|
+
rubocop (~> 1.61)
|
100
|
+
rubocop-performance (1.21.1)
|
101
|
+
rubocop (>= 1.48.1, < 2.0)
|
102
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
103
|
+
rubocop-rails (2.24.1)
|
104
|
+
activesupport (>= 4.2.0)
|
105
|
+
rack (>= 1.1)
|
106
|
+
rubocop (>= 1.33.0, < 2.0)
|
107
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
108
|
+
rubocop-rake (0.6.0)
|
109
|
+
rubocop (~> 1.0)
|
110
|
+
rubocop-rspec (2.29.2)
|
111
|
+
rubocop (~> 1.40)
|
112
|
+
rubocop-capybara (~> 2.17)
|
113
|
+
rubocop-factory_bot (~> 2.22)
|
114
|
+
rubocop-rspec_rails (~> 2.28)
|
115
|
+
rubocop-rspec_rails (2.29.1)
|
116
|
+
rubocop (~> 1.61)
|
117
|
+
rubocop-sequel (0.3.4)
|
118
|
+
rubocop (~> 1.0)
|
119
|
+
ruby-progressbar (1.13.0)
|
120
|
+
sequel (5.84.0)
|
121
|
+
bigdecimal
|
122
|
+
simplecov (0.22.0)
|
123
|
+
docile (~> 1.1)
|
124
|
+
simplecov-html (~> 0.11)
|
125
|
+
simplecov_json_formatter (~> 0.1)
|
126
|
+
simplecov-html (0.13.1)
|
127
|
+
simplecov-lcov (0.8.0)
|
128
|
+
simplecov_json_formatter (0.1.4)
|
129
|
+
symbiont-ruby (0.7.0)
|
130
|
+
timers (4.3.5)
|
131
|
+
tzinfo (2.0.6)
|
132
|
+
concurrent-ruby (~> 1.0)
|
133
|
+
unicode-display_width (2.6.0)
|
134
|
+
|
135
|
+
PLATFORMS
|
136
|
+
arm64-darwin-23
|
137
|
+
ruby
|
138
|
+
|
139
|
+
DEPENDENCIES
|
140
|
+
async
|
141
|
+
money
|
142
|
+
pg
|
143
|
+
pry
|
144
|
+
rake
|
145
|
+
rspec
|
146
|
+
rubocop-config-umbrellio
|
147
|
+
simplecov
|
148
|
+
simplecov-lcov
|
149
|
+
symbiont-ruby
|
150
|
+
umbrellio-sequel-plugins!
|
151
|
+
|
152
|
+
BUNDLED WITH
|
153
|
+
2.5.18
|
data/README.md
CHANGED
@@ -485,6 +485,130 @@ Overrides Rails default `dbconsole` and `db` commands. In order to use it, you h
|
|
485
485
|
require "umbrellio_sequel_plugins/rails_db_command"
|
486
486
|
```
|
487
487
|
|
488
|
+
# Database Tasks for ClickHouse and Sequel
|
489
|
+
|
490
|
+
## ClickHouse Rake Tasks
|
491
|
+
|
492
|
+
We have added a set of Rake tasks to manage ClickHouse database migrations and database operations. These tasks are located in the `namespace :ch`.
|
493
|
+
|
494
|
+
### Task: `ch:create`
|
495
|
+
|
496
|
+
Creates a ClickHouse database in the specified cluster.
|
497
|
+
|
498
|
+
```bash
|
499
|
+
rake ch:create
|
500
|
+
```
|
501
|
+
This task will create a ClickHouse database as defined in the configuration file with the option to specify the cluster using the ClickHouse.config.database.
|
502
|
+
|
503
|
+
Example:
|
504
|
+
```ruby
|
505
|
+
ClickHouse.config do |config|
|
506
|
+
config.assign Rails.application.config_for(:clickhouse)
|
507
|
+
end
|
508
|
+
```
|
509
|
+
|
510
|
+
### Task: `ch:create_migration_table`
|
511
|
+
|
512
|
+
Creates a migration tracking table for ClickHouse in PostgreSQL. This table will be used to track applied migrations for the ClickHouse database.
|
513
|
+
|
514
|
+
```bash
|
515
|
+
rake ch:create_migration_table
|
516
|
+
```
|
517
|
+
|
518
|
+
### Task: `ch:drop`
|
519
|
+
|
520
|
+
Drops the ClickHouse database and truncates the migration tracking table.
|
521
|
+
|
522
|
+
```bash
|
523
|
+
rake ch:drop
|
524
|
+
```
|
525
|
+
|
526
|
+
### Task: `ch:migrate`
|
527
|
+
|
528
|
+
Runs the migrations for the ClickHouse database from the db/migrate/clickhouse directory.
|
529
|
+
|
530
|
+
```bash
|
531
|
+
rake ch:migrate
|
532
|
+
```
|
533
|
+
|
534
|
+
You can specify a version to migrate to using the VERSION environment variable.
|
535
|
+
|
536
|
+
### Task: `ch:rollback`
|
537
|
+
|
538
|
+
Rollbacks the migrations for the ClickHouse database to a specified version.
|
539
|
+
|
540
|
+
```bash
|
541
|
+
rake ch:rollback VERSION=<version_number>
|
542
|
+
```
|
543
|
+
|
544
|
+
If no version is provided, it rolls back the last migration.
|
545
|
+
|
546
|
+
### Task: `ch:reset`
|
547
|
+
|
548
|
+
Drops, recreates, and runs all migrations for the ClickHouse database. This is useful for resetting the entire ClickHouse setup.
|
549
|
+
|
550
|
+
```bash
|
551
|
+
rake ch:reset
|
552
|
+
```
|
553
|
+
|
554
|
+
### Task: `ch:rollback_missing_migrations`
|
555
|
+
|
556
|
+
Rollbacks any missing migrations for the ClickHouse database by comparing applied migrations to the available migration files.
|
557
|
+
|
558
|
+
```bash
|
559
|
+
rake ch:rollback_missing_migrations
|
560
|
+
```
|
561
|
+
|
562
|
+
### Sequel Rake Tasks
|
563
|
+
|
564
|
+
Several tasks have been added under the namespace :sequel to provide better management of migrations and rollbacks in Sequel. These tasks help in managing PostgreSQL and ClickHouse migrations.
|
565
|
+
|
566
|
+
### Task: `sequel:archive_migrations`
|
567
|
+
|
568
|
+
Archives migration source code into a PostgreSQL table for tracking purposes. This task can now accept custom paths for migrations and source tables.
|
569
|
+
|
570
|
+
```bash
|
571
|
+
rake sequel:archive_migrations[migrations_path, migration_table_source]
|
572
|
+
```
|
573
|
+
|
574
|
+
- `migrations_path`: Path to the migration files (default is `db/migrate/*.rb`).
|
575
|
+
- `migration_table_source`: Table to store migration source code (default is `:schema_migrations_sources`).
|
576
|
+
|
577
|
+
### `Task: sequel:rollback_archived_migrations`
|
578
|
+
|
579
|
+
Rollbacks migrations that were applied but are no longer present in the current release. The task supports additional options such as custom migration paths, tables, and transaction settings.
|
580
|
+
|
581
|
+
```bash
|
582
|
+
rake sequel:rollback_archived_migrations[migrations_path, migration_table, migration_table_source, use_transactions]
|
583
|
+
```
|
584
|
+
|
585
|
+
- `migrations_path`: Path to the migration files (default is `db/migrate/*.rb`).
|
586
|
+
- `migration_table`: Table used to track applied migrations (default is `:schema_migrations`).
|
587
|
+
- `migration_table_source`: Table storing migration source code (default is `:schema_migrations_sources`).
|
588
|
+
- `use_transactions`: Whether to use transactions for rolling back (default is `false`).
|
589
|
+
|
590
|
+
### Task: `sequel:rollback_missing_migrations`
|
591
|
+
|
592
|
+
Rollbacks migrations that are absent in the current release when deploying to staging or production. This task helps ensure consistency between different versions.
|
593
|
+
|
594
|
+
```bash
|
595
|
+
rake sequel:rollback_missing_migrations[table, use_transactions]
|
596
|
+
```
|
597
|
+
|
598
|
+
- `table`: The table used to track migrations (optional).
|
599
|
+
- `use_transactions`: Whether to use transactions during rollback (default is `false`).
|
600
|
+
|
601
|
+
### Task: `sequel:rollback_missing_migrations`
|
602
|
+
|
603
|
+
This task specifically helps during deployment by rolling back any migrations that are not present in the current release.
|
604
|
+
|
605
|
+
```bash
|
606
|
+
rake sequel:rollback_missing_migrations[table, use_transactions]
|
607
|
+
```
|
608
|
+
|
609
|
+
- `table`: The table used to track migrations (optional).
|
610
|
+
- `use_transactions`: Whether or not to use transactions when rolling back (optional).
|
611
|
+
|
488
612
|
## License
|
489
613
|
|
490
614
|
Released under MIT License.
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nocov:
|
4
|
+
module Clickhouse
|
5
|
+
module Migrator
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def migrate(to: nil)
|
9
|
+
if to.present?
|
10
|
+
migrator(target: to.to_i).run
|
11
|
+
else
|
12
|
+
migrator.run
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def rollback(to: nil)
|
17
|
+
target = to || migrator.applied_migrations.reverse[1]
|
18
|
+
migrator(target: target.to_i).run
|
19
|
+
end
|
20
|
+
|
21
|
+
def migrator(**opts)
|
22
|
+
Sequel::TimestampMigrator.new(
|
23
|
+
DB,
|
24
|
+
Rails.root.join("db/migrate/clickhouse"),
|
25
|
+
table: :clickhouse_migrations,
|
26
|
+
use_transactions: false,
|
27
|
+
**opts,
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
# :nocov:
|
@@ -77,14 +77,8 @@ module Sequel::ConnectionPoolPatch
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
Sequel::ConnectionPool::ClassMethods.prepend(Sequel::ConnectionPoolPatch)
|
84
|
-
else
|
85
|
-
class Sequel::ConnectionPool
|
86
|
-
class << self
|
87
|
-
prepend Sequel::ConnectionPoolPatch
|
88
|
-
end
|
80
|
+
class Sequel::ConnectionPool
|
81
|
+
class << self
|
82
|
+
prepend Sequel::ConnectionPoolPatch
|
89
83
|
end
|
90
84
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "clickhouse/migrator"
|
4
|
+
|
5
|
+
namespace :ch do
|
6
|
+
desc "Create a ClickHouse database in the specified cluster"
|
7
|
+
task create: :environment do
|
8
|
+
CH.create_database(ClickHouse.config.database, cluster: "click_cluster")
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Create a migration tracking table for ClickHouse in PostgreSQL"
|
12
|
+
task create_migration_table: :environment do
|
13
|
+
DB.create_table Sequel[:public][:clickhouse_migrations] do
|
14
|
+
column :filename, :text, null: false, primary_key: true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Drop the ClickHouse database and truncate the migration tracking table"
|
19
|
+
task drop: :environment do
|
20
|
+
CH.drop_database(ClickHouse.config.database, cluster: "click_cluster")
|
21
|
+
DB.from(Sequel[:public][:clickhouse_migrations]).truncate
|
22
|
+
DB.from(Sequel[:public][:clickhouse_migrations_sources]).truncate
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Run migrations for the ClickHouse database"
|
26
|
+
task migrate: :environment do
|
27
|
+
path = "db/migrate/clickhouse/*.rb"
|
28
|
+
migrations_table = :clickhouse_migrations
|
29
|
+
migrations_sources_table = :clickhouse_migrations_sources
|
30
|
+
use_transactions = "false"
|
31
|
+
|
32
|
+
Rake::Task["sequel:archive_migrations"].reenable
|
33
|
+
Rake::Task["sequel:archive_migrations"].invoke(path, migrations_sources_table)
|
34
|
+
|
35
|
+
Rake::Task["sequel:rollback_archived_migrations"].reenable
|
36
|
+
Rake::Task["sequel:rollback_archived_migrations"]
|
37
|
+
.invoke(path, migrations_table, migrations_sources_table, use_transactions)
|
38
|
+
|
39
|
+
Clickhouse::Migrator.migrate(to: ENV.fetch("VERSION", nil))
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Rollback migrations for the ClickHouse database"
|
43
|
+
task rollback: :environment do
|
44
|
+
Clickhouse::Migrator.rollback(to: ENV.fetch("VERSION", nil))
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Reset the ClickHouse database: drop, recreate, and run all migrations"
|
48
|
+
task reset: :environment do
|
49
|
+
Rake::Task["ch:drop"].invoke
|
50
|
+
Rake::Task["ch:create"].invoke
|
51
|
+
Rake::Task["ch:migrate"].invoke
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "Rollback any missing migrations for ClickHouse"
|
55
|
+
task rollback_missing_migrations: :environment do
|
56
|
+
Rake::Task["sequel:rollback_missing_migrations"].reenable
|
57
|
+
Rake::Task["sequel:rollback_missing_migrations"].invoke(:clickhouse_migrations, "false")
|
58
|
+
end
|
59
|
+
end
|
@@ -2,14 +2,18 @@
|
|
2
2
|
|
3
3
|
namespace :sequel do
|
4
4
|
desc "Archive migrations source code"
|
5
|
-
task archive_migrations
|
6
|
-
|
5
|
+
task :archive_migrations,
|
6
|
+
[:migrations_path, :migration_table_source] => :environment do |_t, args|
|
7
|
+
migrations_path = args[:migrations_path] || "db/migrate/*.rb"
|
8
|
+
migration_table_source = args[:migration_table_source]&.to_sym || :schema_migrations_sources
|
9
|
+
|
10
|
+
DB.create_table?(migration_table_source) do
|
7
11
|
column :version, "numeric", primary_key: true
|
8
12
|
column :filename, "text", null: false
|
9
13
|
column :source, "text", null: false
|
10
14
|
end
|
11
15
|
|
12
|
-
migrations = Rails.root.glob(
|
16
|
+
migrations = Rails.root.glob(migrations_path).map do |file|
|
13
17
|
filename = file.basename.to_s
|
14
18
|
{ version: filename.to_i, filename: filename, source: file.read }
|
15
19
|
end
|
@@ -19,6 +23,6 @@ namespace :sequel do
|
|
19
23
|
update: { filename: Sequel[:excluded][:filename], source: Sequel[:excluded][:source] },
|
20
24
|
}
|
21
25
|
|
22
|
-
DB[
|
26
|
+
DB[migration_table_source].insert_conflict(**conflict_options).multi_insert(migrations)
|
23
27
|
end
|
24
28
|
end
|
@@ -4,19 +4,30 @@ require "sequel/timestamp_migrator_undo_extension"
|
|
4
4
|
|
5
5
|
namespace :sequel do
|
6
6
|
desc "Rollback migrations that were applied earlier but are not present in current release"
|
7
|
-
task rollback_archived_migrations
|
7
|
+
task :rollback_archived_migrations,
|
8
|
+
[:migrations_path, :migration_table, :migration_table_source,
|
9
|
+
:use_transactions] => :environment do |_t, args|
|
10
|
+
migrations_path = args[:migrations_path] || "db/migrate/*.rb"
|
11
|
+
migration_table_source = args[:migration_table_source]&.to_sym || :schema_migrations_sources
|
12
|
+
use_transactions = args[:use_transactions].nil? ? nil : args[:use_transactions] == "true"
|
13
|
+
|
8
14
|
DB.log_info("Finding applied migrations not present in current release...")
|
9
15
|
|
10
16
|
Dir.mktmpdir do |tmpdir|
|
11
|
-
DB[
|
17
|
+
DB[migration_table_source].each do |migration|
|
12
18
|
path = File.join(tmpdir, migration.fetch(:filename))
|
13
19
|
File.write(path, migration.fetch(:source))
|
14
20
|
end
|
15
21
|
|
16
|
-
|
22
|
+
migrator_args = {
|
23
|
+
table: args[:migration_table],
|
24
|
+
use_transactions: use_transactions,
|
25
|
+
allow_missing_migration_files: false,
|
26
|
+
}.compact
|
27
|
+
migrator = Sequel::TimestampMigrator.new(DB, tmpdir, migrator_args)
|
17
28
|
|
18
29
|
applied_migrations = migrator.applied_migrations.map(&:to_i)
|
19
|
-
filesystem_migrations = Rails.root.glob(
|
30
|
+
filesystem_migrations = Rails.root.glob(migrations_path).map { |x| File.basename(x).to_i }
|
20
31
|
missing_migrations = applied_migrations - filesystem_migrations
|
21
32
|
|
22
33
|
if missing_migrations.any?
|
@@ -4,7 +4,9 @@ require "sequel/timestamp_migrator_undo_extension"
|
|
4
4
|
|
5
5
|
namespace :sequel do
|
6
6
|
desc "Rollback migrations that are absent in revision when deploying on staging"
|
7
|
-
task rollback_missing_migrations: :environment do
|
7
|
+
task :rollback_missing_migrations, [:table, :use_transactions] => :environment do |_t, args|
|
8
|
+
use_transactions = args[:use_transactions].nil? ? nil : args[:use_transactions] == "true"
|
9
|
+
|
8
10
|
extract_migrations = lambda do |path|
|
9
11
|
Dir.glob("#{path}/db/migrate/*.rb").map { |filename| File.basename(filename).to_i }
|
10
12
|
end
|
@@ -19,7 +21,12 @@ namespace :sequel do
|
|
19
21
|
puts migrations_to_rollback
|
20
22
|
|
21
23
|
path = Rails.root.join("db/migrate")
|
22
|
-
|
24
|
+
migrator_args = {
|
25
|
+
table: args[:table],
|
26
|
+
use_transactions: use_transactions,
|
27
|
+
allow_missing_migration_files: false,
|
28
|
+
}.compact
|
29
|
+
migrator = Sequel::TimestampMigrator.new(DB, path, migrator_args)
|
23
30
|
applied_migrations = migrator.applied_migrations.map(&:to_i)
|
24
31
|
migrations = applied_migrations.select { |m| m.in?(migrations_to_rollback) }.sort.reverse
|
25
32
|
|
@@ -4,14 +4,8 @@ lib = File.expand_path("lib", __dir__)
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
gem_version = "0.16.0"
|
8
|
-
|
9
|
-
if ENV.fetch("PUBLISH_JOB", nil)
|
10
|
-
release_version = "#{gem_version}.#{ENV.fetch("GITHUB_RUN_NUMBER")}"
|
11
|
-
end
|
12
|
-
|
13
7
|
spec.name = "umbrellio-sequel-plugins"
|
14
|
-
spec.version =
|
8
|
+
spec.version = "0.17.0"
|
15
9
|
spec.required_ruby_version = ">= 3.0"
|
16
10
|
|
17
11
|
spec.authors = ["Team Umbrellio"]
|
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.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Team Umbrellio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -36,11 +36,13 @@ files:
|
|
36
36
|
- ".rspec"
|
37
37
|
- ".rubocop.yml"
|
38
38
|
- Gemfile
|
39
|
+
- Gemfile.lock
|
39
40
|
- LICENSE
|
40
41
|
- README.md
|
41
42
|
- Rakefile
|
42
43
|
- bin/console
|
43
44
|
- bin/setup
|
45
|
+
- lib/clickhouse/migrator.rb
|
44
46
|
- lib/sequel/extensions/currency_rates.rb
|
45
47
|
- lib/sequel/extensions/deferrable_foreign_keys.rb
|
46
48
|
- lib/sequel/extensions/fibered_connection_pool.rb
|
@@ -60,6 +62,7 @@ files:
|
|
60
62
|
- lib/sequel/plugins/upsert.rb
|
61
63
|
- lib/sequel/plugins/with_lock.rb
|
62
64
|
- lib/sequel/timestamp_migrator_undo_extension.rb
|
65
|
+
- lib/tasks/clickhouse.rake
|
63
66
|
- lib/tasks/sequel/archive_migrations.rake
|
64
67
|
- lib/tasks/sequel/rollback_archived_migrations.rake
|
65
68
|
- lib/tasks/sequel/rollback_missing_migrations.rake
|