sequel-data-migrate 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/lib/sequel_data/migrate/migrator.rb +33 -31
- data/lib/sequel_data/migrate/version.rb +1 -1
- data/sig/sequel_data/migrate.rbs +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a03e567fda7ed849e9a70868d7395a1d9d4a8584b3027c4e9f21ad0ad73ef2f
|
4
|
+
data.tar.gz: 852e56344cc564be33d1028b504b735c42195d09a12e982bd148ce7435dd80c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a7231580196995771534f090b14e2c92a941465a60779716e125606719c682fb3cf1a8bb23a65c6f84e1842a372a5816db3be9c1e61caea77f166b75f691ac0
|
7
|
+
data.tar.gz: bc2017007f8fa13551e49674d1be6f6f2120c8380baec8f1d961ef6e2d57b464566f76a8ed9a4f027c664ae54c3780becd433b13e8cee4ea2bfd46dab5cd0ac8
|
data/CHANGELOG.md
CHANGED
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
|
42
|
-
|
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
|
|
@@ -15,39 +15,41 @@ module SequelData
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def migrate
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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)
|
data/sig/sequel_data/migrate.rbs
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|