litestream 0.7.2-x86_64-linux → 0.9.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fc80c60f00f49af0aa809eb1105a801c456e4ce7a1c025fb52b006316a86fc5
4
- data.tar.gz: 15745f36c2e10d154e109763de84098285eeb4d2c5b4c8464b171eb597510817
3
+ metadata.gz: 7ce26bfd1f1653d96303a109f652aa041f24eeb11b8df7a64ad1172f1630adf0
4
+ data.tar.gz: 3570aa252e1a755c6dc78bc5e720fda47fc7ea340d0a81ab816a766056757f18
5
5
  SHA512:
6
- metadata.gz: bf8212c25a33f8c0b6d0724384409991fa94822be7b4054c62bc790d4cbf4755e347e4f253b01865d02e9016c4290cbdcf608299f0f62b927b232e3ffeb17a3d
7
- data.tar.gz: 55f6ec8f7c9f1c5071533fd47a207011a0a2d18bc8361de85e1249acef07b7e19b1d0c6bea86b2c1a86a1768fcfffec82458ef7d24602fcaf83774793385a7a2
6
+ metadata.gz: 8d0ddf78cfc460f6652b8664b0f31246b745451b01f675695fb28cba646874bca31e39c62af51363ddc99e45dd023fdd0e2cec0efbd9a888009e0318f3ba5dd1
7
+ data.tar.gz: 57520e534e247b47b3898269b3c36dc754869694c9ad2cb896292ee6bb66b6c5fcb56691d64030ef6d7831b991b3b264e1775304cff355ca14c7d754e13ad12e
@@ -102,16 +102,29 @@ module Litestream
102
102
  }.merge(argv)
103
103
  restore(database, async: false, **args)
104
104
 
105
- restored_tables_count = `sqlite3 #{backup} "select count(*) from sqlite_schema where type='table';"`.chomp.to_i
106
- restored_size = File.size(backup)
107
- original_tables_count = `sqlite3 #{database} "select count(*) from sqlite_schema where type='table';"`.chomp.to_i
108
- original_size = File.size(database)
105
+ restored_schema = `sqlite3 #{backup} "select name, type from sqlite_schema;"`.chomp.split("\n")
106
+ restored_data = restored_schema.map { _1.split("|") }.group_by(&:last)
107
+ restored_rows_count = restored_data["table"]&.sum { |tbl, _| `sqlite3 #{backup} "select count(*) from #{tbl};"`.chomp.to_i }
108
+
109
+ original_schema = `sqlite3 #{database} "select name, type from sqlite_schema;"`.chomp.split("\n")
110
+ original_data = original_schema.map { _1.split("|") }.group_by(&:last)
111
+ original_rows_count = original_data["table"]&.sum { |tbl, _| `sqlite3 #{database} "select count(*) from #{tbl};"`.chomp.to_i }
109
112
 
110
113
  Dir.glob(backup + "*").each { |file| File.delete(file) }
111
114
 
112
115
  {
113
- "size" => {"original" => original_size, "restored" => restored_size},
114
- "tables" => {"original" => original_tables_count, "restored" => restored_tables_count}
116
+ "original" => {
117
+ "path" => database,
118
+ "tables" => original_data["table"]&.size,
119
+ "indexes" => original_data["index"]&.size,
120
+ "rows" => original_rows_count
121
+ },
122
+ "restored" => {
123
+ "path" => backup,
124
+ "tables" => restored_data["table"]&.size,
125
+ "indexes" => restored_data["index"]&.size,
126
+ "rows" => restored_rows_count
127
+ }
115
128
  }
116
129
  end
117
130
 
@@ -1,3 +1,3 @@
1
1
  module Litestream
2
- VERSION = "0.7.2"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -93,18 +93,53 @@ namespace :litestream do
93
93
  options.symbolize_keys!
94
94
 
95
95
  result = Litestream::Commands.verify(database, async: true, **options)
96
-
97
- puts <<~TXT if result
98
-
99
- size
100
- original #{result["size"]["original"]}
101
- restored #{result["size"]["restored"]}
102
- delta #{result["size"]["original"] - result["size"]["restored"]}
103
-
104
- tables
105
- original #{result["tables"]["original"]}
106
- restored #{result["tables"]["restored"]}
107
- delta #{result["tables"]["original"] - result["tables"]["restored"]}
108
- TXT
96
+ original_tables = result["original"]["tables"]
97
+ restored_tables = result["restored"]["tables"]
98
+ original_indexes = result["original"]["indexes"]
99
+ restored_indexes = result["restored"]["indexes"]
100
+ original_rows = result["original"]["rows"]
101
+ restored_rows = result["restored"]["rows"]
102
+
103
+ same_number_of_tables = original_tables == restored_tables
104
+ same_number_of_indexes = original_indexes == restored_indexes
105
+ same_number_of_rows = original_rows == restored_rows
106
+
107
+ if same_number_of_tables && same_number_of_indexes && same_number_of_rows
108
+ puts "Backup for `#{database}` verified as consistent!\n" + [
109
+ " tables #{original_tables}",
110
+ " indexes #{original_indexes}",
111
+ " rows #{original_rows}"
112
+ ].compact.join("\n")
113
+ else
114
+ abort "Verification failed for #{database}:\n" + [
115
+ (unless same_number_of_tables
116
+ if original_tables > restored_tables
117
+ diff = original_tables - restored_tables
118
+ " Backup is missing #{diff} table#{"s" if diff > 1}"
119
+ else
120
+ diff = restored_tables - original_tables
121
+ " Backup has extra #{diff} table#{"s" if diff > 1}"
122
+ end
123
+ end),
124
+ (unless same_number_of_indexes
125
+ if original_indexes > restored_indexes
126
+ diff = original_indexes - restored_indexes
127
+ " Backup is missing #{diff} index#{"es" if diff > 1}"
128
+ else
129
+ diff = restored_indexes - original_indexes
130
+ " Backup has extra #{diff} index#{"es" if diff > 1}"
131
+ end
132
+ end),
133
+ (unless same_number_of_rows
134
+ if original_rows > restored_rows
135
+ diff = original_rows - restored_rows
136
+ " Backup is missing #{diff} row#{"s" if diff > 1}"
137
+ else
138
+ diff = restored_rows - original_rows
139
+ " Backup has extra #{diff} row#{"s" if diff > 1}"
140
+ end
141
+ end)
142
+ ].compact.join("\n")
143
+ end
109
144
  end
110
145
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: litestream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.9.0
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Stephen Margheim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-02 00:00:00.000000000 Z
11
+ date: 2024-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logfmt