actual_db_schema 0.6.0 → 0.7.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/actual_db_schema/commands/list.rb +47 -6
- data/lib/actual_db_schema/git.rb +12 -0
- data/lib/actual_db_schema/patches/migration_proxy.rb +1 -1
- data/lib/actual_db_schema/store.rb +43 -0
- data/lib/actual_db_schema/version.rb +1 -1
- data/lib/actual_db_schema.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 957b11aa8112a41c4cc875a2c34510e651c9f41b94ab76c86b765f3f89501a27
|
4
|
+
data.tar.gz: b1d2c2a81647bb18b6a1b3bce71691ff3cac4cd809585a4830bc332a3b135df5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fc19c47a665af2efc5bc1e5e1d37cf8335f11d5f7c3e248e67cfb5d044d69fd626890b31e539f8f0e0fc3f63bdd36ecd3ce624383c42a1320bed9632a037242
|
7
|
+
data.tar.gz: d1af7d177e1dfbd9f7e69e502e5e55d7b73906c0d63b6a3c125ff4af311994feb3b1c5a97ba9eca321a7a8e2aa791016ee3e8de7baffda598f6eb5dcabb10ade
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -63,7 +63,7 @@ The gem offers the following rake tasks that can be manually run according to yo
|
|
63
63
|
|
64
64
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
65
65
|
|
66
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
66
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, update the CHANGELOG, make the commit, push, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
67
67
|
|
68
68
|
## Contributing
|
69
69
|
|
@@ -20,18 +20,59 @@ module ActualDbSchema
|
|
20
20
|
puts "Below is a list of irrelevant migrations executed in unmerged branches."
|
21
21
|
puts "To bring your database schema up to date, the migrations marked as \"up\" should be rolled back."
|
22
22
|
puts "\ndatabase: #{ActiveRecord::Base.connection_db_config.database}\n\n"
|
23
|
-
puts
|
24
|
-
puts "-" *
|
23
|
+
puts header.join(" ")
|
24
|
+
puts "-" * separator_width
|
25
|
+
end
|
26
|
+
|
27
|
+
def separator_width
|
28
|
+
header.map(&:length).sum + (header.size - 1) * 2
|
29
|
+
end
|
30
|
+
|
31
|
+
def header
|
32
|
+
@header ||=
|
33
|
+
[
|
34
|
+
"Status".center(8),
|
35
|
+
"Migration ID".ljust(14),
|
36
|
+
"Branch".ljust(branch_column_width),
|
37
|
+
"Migration File".ljust(16)
|
38
|
+
]
|
25
39
|
end
|
26
40
|
|
27
41
|
def table
|
28
42
|
context.migrations_status.each do |status, version|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
puts %(#{status.center(8)} #{version.to_s.ljust(14)} #{migration.filename.gsub("#{Rails.root}/", "")})
|
43
|
+
line = line_for(status, version)
|
44
|
+
puts line if line
|
33
45
|
end
|
34
46
|
end
|
47
|
+
|
48
|
+
def line_for(status, version)
|
49
|
+
migration = indexed_phantom_migrations[version]
|
50
|
+
return unless migration
|
51
|
+
|
52
|
+
[
|
53
|
+
status.center(8),
|
54
|
+
version.to_s.ljust(14),
|
55
|
+
branch_for(version).ljust(branch_column_width),
|
56
|
+
migration.filename.gsub("#{Rails.root}/", "")
|
57
|
+
].join(" ")
|
58
|
+
end
|
59
|
+
|
60
|
+
def branch_for(version)
|
61
|
+
metadata.fetch(version, {})[:branch] || "unknown"
|
62
|
+
end
|
63
|
+
|
64
|
+
def metadata
|
65
|
+
@metadata ||= ActualDbSchema::Store.instance.read
|
66
|
+
end
|
67
|
+
|
68
|
+
def longest_branch_name
|
69
|
+
@longest_branch_name ||=
|
70
|
+
metadata.values.map { |v| v[:branch] }.compact.max_by(&:length) || "unknown"
|
71
|
+
end
|
72
|
+
|
73
|
+
def branch_column_width
|
74
|
+
longest_branch_name.length
|
75
|
+
end
|
35
76
|
end
|
36
77
|
end
|
37
78
|
end
|
@@ -6,7 +6,7 @@ module ActualDbSchema
|
|
6
6
|
module MigrationProxy
|
7
7
|
def migrate(direction)
|
8
8
|
super(direction)
|
9
|
-
|
9
|
+
ActualDbSchema::Store.instance.write(filename) if direction == :up
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActualDbSchema
|
4
|
+
# Stores the migrated files into the tmp folder
|
5
|
+
class Store
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
Item = Struct.new(:version, :timestamp, :branch)
|
9
|
+
|
10
|
+
def write(filename)
|
11
|
+
basename = File.basename(filename)
|
12
|
+
FileUtils.copy(filename, folder.join(basename))
|
13
|
+
record_metadata(filename)
|
14
|
+
end
|
15
|
+
|
16
|
+
def read
|
17
|
+
return {} unless File.exist?(store_file)
|
18
|
+
|
19
|
+
CSV.read(store_file).map { |line| Item.new(*line) }.index_by(&:version)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def record_metadata(filename)
|
25
|
+
version = File.basename(filename).scan(/(\d+)_.*\.rb/).first.first
|
26
|
+
CSV.open(store_file, "a") do |csv|
|
27
|
+
csv << [
|
28
|
+
version,
|
29
|
+
Time.current.iso8601,
|
30
|
+
Git.current_branch
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def folder
|
36
|
+
ActualDbSchema.migrated_folder
|
37
|
+
end
|
38
|
+
|
39
|
+
def store_file
|
40
|
+
folder.join("metadata.csv")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/actual_db_schema.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_record/migration"
|
4
|
+
require "csv"
|
5
|
+
require_relative "actual_db_schema/git"
|
6
|
+
require_relative "actual_db_schema/store"
|
4
7
|
require_relative "actual_db_schema/version"
|
5
8
|
require_relative "actual_db_schema/patches/migration_proxy"
|
6
9
|
require_relative "actual_db_schema/patches/migrator"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actual_db_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Kaleshka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -122,9 +122,11 @@ files:
|
|
122
122
|
- lib/actual_db_schema/commands/base.rb
|
123
123
|
- lib/actual_db_schema/commands/list.rb
|
124
124
|
- lib/actual_db_schema/commands/rollback.rb
|
125
|
+
- lib/actual_db_schema/git.rb
|
125
126
|
- lib/actual_db_schema/patches/migration_context.rb
|
126
127
|
- lib/actual_db_schema/patches/migration_proxy.rb
|
127
128
|
- lib/actual_db_schema/patches/migrator.rb
|
129
|
+
- lib/actual_db_schema/store.rb
|
128
130
|
- lib/actual_db_schema/version.rb
|
129
131
|
- lib/railtie.rb
|
130
132
|
- lib/tasks/db.rake
|