ec-pg 0.1.4 → 0.1.6
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 +4 -4
- data/lib/ec/pg/migrator.rb +20 -14
- data/lib/ec/pg/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 96db794a56eb50815839a716d668cb9cb1309ab19e9a7dca540f72d67c6aa0b3
|
|
4
|
+
data.tar.gz: 1a5ab8f3fc64bac9aaa3f965bb1698015e2d639af3819077dc051f7ae1bd016c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 49b2648cdd99f5849d2aff3cfc55c49711aceef2e6a5d86ea7b66a19c3330daa2a2f3e382927aadd45b9a18d35984b064ed355e761a244b91ebfdaf227d87d06
|
|
7
|
+
data.tar.gz: 73222c5fb6ef8dce5392fb4bf63a8a9b08fb93fd1d10d85df0648e06e4f18346e949a548ea90ca038112840771f0d403241f5ded7f64dbd9858840d6e6d25029
|
data/lib/ec/pg/migrator.rb
CHANGED
|
@@ -14,9 +14,9 @@ module Ec
|
|
|
14
14
|
Ec::Pg::SchemaMixin.registered_models.each do |model|
|
|
15
15
|
model.schemas.each do |shard, schemas|
|
|
16
16
|
Ec::Pg.switch(shard: shard) do
|
|
17
|
-
schemas.each do |
|
|
18
|
-
Ec::Pg.dprint("migrating model: #{model}, shard: #{shard}, schema: #{
|
|
19
|
-
migrate_schema(model.connection
|
|
17
|
+
schemas.each do |schema_name|
|
|
18
|
+
Ec::Pg.dprint("migrating model: #{model}, shard: #{shard}, schema: #{schema_name}".red)
|
|
19
|
+
migrate_schema(model.connection, schema_name)
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
end
|
|
@@ -29,9 +29,9 @@ module Ec
|
|
|
29
29
|
Ec::Pg::SchemaMixin.registered_models.each do |model|
|
|
30
30
|
model.schemas.each do |shard, schemas|
|
|
31
31
|
Ec::Pg.switch(shard: shard) do
|
|
32
|
-
schemas.each do |
|
|
33
|
-
Ec::Pg.dprint("rolling back model: #{model}, shard: #{shard}, schema: #{
|
|
34
|
-
rollback_schema(model.connection
|
|
32
|
+
schemas.each do |schema_name|
|
|
33
|
+
Ec::Pg.dprint("rolling back model: #{model}, shard: #{shard}, schema: #{schema_name}".red)
|
|
34
|
+
rollback_schema(model.connection, schema_name, steps)
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -41,16 +41,22 @@ module Ec
|
|
|
41
41
|
|
|
42
42
|
private
|
|
43
43
|
|
|
44
|
-
def rollback_schema(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
def rollback_schema(connection, schema_name, steps)
|
|
45
|
+
with_pool(connection, schema_name) do |pool|
|
|
46
|
+
pool.migration_context.rollback(steps)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def migrate_schema(connection, schema_name)
|
|
51
|
+
with_pool(connection, schema_name) do |pool|
|
|
52
|
+
pool.migration_context.migrate
|
|
53
|
+
end
|
|
48
54
|
end
|
|
49
55
|
|
|
50
|
-
def
|
|
51
|
-
ActiveRecord::Base.establish_connection(pool.db_config)
|
|
52
|
-
|
|
53
|
-
pool
|
|
56
|
+
def with_pool(connection, schema_name)
|
|
57
|
+
ActiveRecord::Base.establish_connection(connection.pool.db_config)
|
|
58
|
+
connection.schema_search_path = schema_name
|
|
59
|
+
yield(connection.pool)
|
|
54
60
|
end
|
|
55
61
|
end
|
|
56
62
|
end
|
data/lib/ec/pg/version.rb
CHANGED