ci-helper 0.8.0 → 0.9.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c5d7ac1dcb58a235887b801308afcfa0e6f4cee4a52c829c769d12424866107
|
4
|
+
data.tar.gz: 446bfe1be5110ece9d61eec181a4718999bd20e0c7f70e2f3fcf04b3c9b7f72f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b35b1ea59c8fb0eb4bd2c293f807c4a421b6326852f3fb8e7a879f8c6a5a05dc5010e4f494846236c5733f2a59fec89b7994c4295b9254c49bc237a8acb92aa
|
7
|
+
data.tar.gz: 9cb25a481ea5c3d03afd5fbc45f276454a88c880d1296b24b898941305b50ef1144fd8df84447e897cf8d9edb0757aef4f82a6591a9ff0b3a5f6e40c6a0be9bc
|
data/Gemfile.lock
CHANGED
@@ -6,6 +6,8 @@ module CIHelper
|
|
6
6
|
def call
|
7
7
|
create_and_migrate_database!
|
8
8
|
execute("bundle exec rake db:seed")
|
9
|
+
create_and_migrate_clickhouse_database! if with_clickhouse?
|
10
|
+
0
|
9
11
|
end
|
10
12
|
|
11
13
|
private
|
@@ -13,6 +15,10 @@ module CIHelper
|
|
13
15
|
def env
|
14
16
|
:development
|
15
17
|
end
|
18
|
+
|
19
|
+
def with_clickhouse?
|
20
|
+
boolean_option(:with_clickhouse)
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
@@ -7,6 +7,13 @@ module CIHelper
|
|
7
7
|
create_and_migrate_database!
|
8
8
|
execute_with_env("bundle exec rake db:rollback_new_migrations")
|
9
9
|
execute_with_env("bundle exec rake db:migrate")
|
10
|
+
|
11
|
+
if with_clickhouse?
|
12
|
+
create_and_migrate_clickhouse_database!
|
13
|
+
execute_with_env("bundle exec rake ch:rollback_new_migrations")
|
14
|
+
execute_with_env("bundle exec rake ch:migrate")
|
15
|
+
end
|
16
|
+
0
|
10
17
|
end
|
11
18
|
|
12
19
|
private
|
@@ -14,6 +21,10 @@ module CIHelper
|
|
14
21
|
def env
|
15
22
|
:test
|
16
23
|
end
|
24
|
+
|
25
|
+
def with_clickhouse?
|
26
|
+
boolean_option(:with_clickhouse)
|
27
|
+
end
|
17
28
|
end
|
18
29
|
end
|
19
30
|
end
|
data/lib/ci_helper/version.rb
CHANGED
@@ -13,6 +13,7 @@ class SequelManagement
|
|
13
13
|
self.logger = Logger.new($stdout)
|
14
14
|
|
15
15
|
define_db_task!
|
16
|
+
define_ch_task!
|
16
17
|
end
|
17
18
|
|
18
19
|
private
|
@@ -23,6 +24,10 @@ class SequelManagement
|
|
23
24
|
self.class::MIGRATIONS_PATH
|
24
25
|
end
|
25
26
|
|
27
|
+
def ch_migrations_path
|
28
|
+
"db/migrate/clickhouse"
|
29
|
+
end
|
30
|
+
|
26
31
|
def define_db_task!
|
27
32
|
namespace :db do
|
28
33
|
desc "Rollback all migrations, which doesn't exist in master branch"
|
@@ -47,6 +52,31 @@ class SequelManagement
|
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
55
|
+
def define_ch_task!
|
56
|
+
namespace :ch do
|
57
|
+
desc "Rollback all migrations, which doesn't exist in master branch"
|
58
|
+
task rollback_new_migrations: :environment do
|
59
|
+
abort "Shouldn't run in production mode!" if Rails.env.production?
|
60
|
+
|
61
|
+
logger.info "Begin rolling back new migrations"
|
62
|
+
|
63
|
+
git_command = "git ls-tree --name-only origin/master #{ch_migrations_path}/"
|
64
|
+
migration_files, error, status = Open3.capture3(git_command)
|
65
|
+
abort "Can't get list of migration files:\n#{error}" unless status.success?
|
66
|
+
|
67
|
+
original_migrations = migration_files.split.map { |path| File.basename(path) }
|
68
|
+
migrations_to_rollback = (ch_migrator.applied_migrations - original_migrations).sort.reverse
|
69
|
+
|
70
|
+
next if migrations_to_rollback.empty?
|
71
|
+
|
72
|
+
logger.info "Rolling back migrations:"
|
73
|
+
logger.info migrations_to_rollback.join("\n")
|
74
|
+
|
75
|
+
ch_rollback!(migrations_to_rollback)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
50
80
|
def git_command
|
51
81
|
"git ls-tree --name-only origin/master #{migrations_path}/"
|
52
82
|
end
|
@@ -58,6 +88,14 @@ class SequelManagement
|
|
58
88
|
end
|
59
89
|
end
|
60
90
|
|
91
|
+
def ch_migrator
|
92
|
+
@ch_migrator ||= begin
|
93
|
+
full_path = Rails.root.join(ch_migrations_path)
|
94
|
+
Sequel::TimestampMigrator.new(DB, full_path, allow_missing_migration_files: true,
|
95
|
+
table: "clickhouse_migrations")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
61
99
|
def rollback!(migrations)
|
62
100
|
migrations.each do |migration|
|
63
101
|
migrator.undo(migration.to_i)
|
@@ -69,6 +107,18 @@ class SequelManagement
|
|
69
107
|
end
|
70
108
|
end
|
71
109
|
end
|
110
|
+
|
111
|
+
def ch_rollback!(migrations)
|
112
|
+
migrations.each do |migration|
|
113
|
+
ch_migrator.undo(migration.to_i)
|
114
|
+
rescue Sequel::Migrator::Error => error
|
115
|
+
if error.message.include?("does not exist in the filesystem")
|
116
|
+
logger.info error.message
|
117
|
+
else
|
118
|
+
raise error
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
72
122
|
end
|
73
123
|
|
74
124
|
SequelManagement.new
|