git-fit 0.7.4 → 0.7.5

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: 8b529b539d17dfce5129f5b5e9a26c87d29fc2c42d01cc28b33663951e019ce2
4
- data.tar.gz: 491038827bc8844b30ec1f42d6f2a13582543419c028710ed4c76329eb2b8cc3
3
+ metadata.gz: 7c031091e27306d5f66a2754029c00d6047d07945b11f1a45a18332a1d0b0e02
4
+ data.tar.gz: 3fb56126e52afdf6f0d89e4aa54665fee7e9dd2fad37f3f3b36cf8b451f0f0eb
5
5
  SHA512:
6
- metadata.gz: 73a4d04e598d30851db5ee28bc74452c4556b18dbbd7a95c82c904072276a0b6afe88ca2662c41682484c771a53dc74f30d5d2939fbe32294bcc56406e640e74
7
- data.tar.gz: 0fdbf72996b45cb0c03fb9f92f156257950632080730f5288e9af056ae63fce74faa53333a323a7290577a2abc64a3da01d330f8d97c6b8261c86533db9ce161
6
+ metadata.gz: ed9cce62705d3685fa03d604e4ae3acaaf68e224779ccaec522ad6d3572a9edfbf24180617ac3aadd6458cef63883606c760f6c59180ab9c094da15332d22af3
7
+ data.tar.gz: '06758cbad1a0e60576a6662cc69b29449d98cd5fb24f3b1fd97b3a2b72bc211fbd59bb19add5b54693fecade1e9b756eccb6dcba8ac9b2d7885cc3da03177d65'
@@ -13,7 +13,9 @@ module GitFit
13
13
 
14
14
  def json
15
15
  config = git_fit_config
16
- db = GitFit::DB::Connection.new(config.db_path).db
16
+ conn = GitFit::DB::Connection.new(config.db_path)
17
+ conn.migrate!
18
+ db = conn.db
17
19
  path = options[:output] || config.export_config.dig("json", "path") || "site/activities.json"
18
20
  filter = options[:activity]&.map(&:strip)&.map(&:downcase)
19
21
  count = Export::JSON.new(db: db, output: path, activity_filter: filter).call
@@ -10,7 +10,9 @@ module GitFit
10
10
  option :"dry-run", type: :boolean, desc: "Don't write to DB"
11
11
  def detect
12
12
  config = GitFit::Config.new
13
- db = GitFit::DB::Connection.new(config.db_path).db
13
+ conn = GitFit::DB::Connection.new(config.db_path)
14
+ conn.migrate!
15
+ db = conn.db
14
16
  amap_key = ENV["AMAP_API_KEY"] || config.sync_config("amap")["api_key"]
15
17
  detector = GitFit::Geo::DivisionDetector.new(
16
18
  db: db,
@@ -18,7 +18,9 @@ module GitFit
18
18
  end
19
19
 
20
20
  config = GitFit::Config.new
21
- db = GitFit::DB::Connection.new(config.db_path).db
21
+ conn = GitFit::DB::Connection.new(config.db_path)
22
+ conn.migrate!
23
+ db = conn.db
22
24
  filter = options[:activity]&.map(&:strip)&.map(&:downcase)
23
25
  time_budget = config.dig("sync", "time_budget")
24
26
  sport_override = options[:sport]
@@ -53,7 +55,9 @@ module GitFit
53
55
  option :sport, type: :string, desc: "Override sport_category for GPX files"
54
56
  def gpx
55
57
  config = GitFit::Config.new
56
- db = GitFit::DB::Connection.new(config.db_path).db
58
+ conn = GitFit::DB::Connection.new(config.db_path)
59
+ conn.migrate!
60
+ db = conn.db
57
61
  filter = options[:activity]&.map(&:strip)&.map(&:downcase)
58
62
  time_budget = config.dig("sync", "time_budget")
59
63
  sport_override = options[:sport]
@@ -84,7 +88,9 @@ module GitFit
84
88
  option :activity, type: :array, desc: "Filter by sport type", aliases: "--act"
85
89
  def tcx
86
90
  config = GitFit::Config.new
87
- db = GitFit::DB::Connection.new(config.db_path).db
91
+ conn = GitFit::DB::Connection.new(config.db_path)
92
+ conn.migrate!
93
+ db = conn.db
88
94
  filter = options[:activity]&.map(&:strip)&.map(&:downcase)
89
95
  time_budget = config.dig("sync", "time_budget")
90
96
 
@@ -113,7 +119,9 @@ module GitFit
113
119
  option :activity, type: :array, desc: "Filter by sport type", aliases: "--act"
114
120
  def fit
115
121
  config = GitFit::Config.new
116
- db = GitFit::DB::Connection.new(config.db_path).db
122
+ conn = GitFit::DB::Connection.new(config.db_path)
123
+ conn.migrate!
124
+ db = conn.db
117
125
  filter = options[:activity]&.map(&:strip)&.map(&:downcase)
118
126
  time_budget = config.dig("sync", "time_budget")
119
127
 
@@ -142,7 +150,9 @@ module GitFit
142
150
  option :activity, type: :array, desc: "Filter by sport type", aliases: "--act"
143
151
  def apple_health
144
152
  config = GitFit::Config.new
145
- db = GitFit::DB::Connection.new(config.db_path).db
153
+ conn = GitFit::DB::Connection.new(config.db_path)
154
+ conn.migrate!
155
+ db = conn.db
146
156
  filter = options[:activity]&.map(&:strip)&.map(&:downcase)
147
157
  time_budget = config.dig("sync", "time_budget")
148
158
 
@@ -10,7 +10,7 @@ module GitFit
10
10
  sources = if source
11
11
  [source]
12
12
  else
13
- configured = (git_fit_config["sync"] || {}).keys
13
+ configured = (git_fit_config["sync"] || {}).select { |_k, v| v.is_a?(Hash) }.keys
14
14
  builtin = GitFit::Sync::Base.adapters
15
15
  .map { |c| c.config_key }
16
16
  if ENV["GIT_FIT_ENVIRONMENT"] == "testing"
data/lib/git_fit/cli.rb CHANGED
@@ -113,7 +113,9 @@ module GitFit
113
113
  end
114
114
 
115
115
  def connect_db
116
- GitFit::DB::Connection.new(git_fit_config.db_path).db
116
+ conn = GitFit::DB::Connection.new(git_fit_config.db_path)
117
+ conn.migrate!
118
+ conn.db
117
119
  end
118
120
 
119
121
  def deep_dup(obj)
@@ -46,7 +46,8 @@ module GitFit
46
46
  end
47
47
 
48
48
  def sync_config(source)
49
- @data.dig("sync", source) || {}
49
+ val = @data.dig("sync", source)
50
+ val.is_a?(Hash) ? val : {}
50
51
  end
51
52
 
52
53
  def privacy_config
@@ -6,7 +6,8 @@ module GitFit
6
6
  desc "migrate", "Run database migrations"
7
7
  def migrate
8
8
  config = GitFit::Config.new
9
- GitFit::DB::Connection.new(config.db_path)
9
+ conn = GitFit::DB::Connection.new(config.db_path)
10
+ conn.migrate!
10
11
  say_status :done, "Migrations up to date", :green
11
12
  rescue => e
12
13
  say_status :error, "Migration failed: #{e.message}", :red
@@ -9,22 +9,49 @@ module GitFit
9
9
  @db = Sequel.sqlite(db_path)
10
10
  @db.run("PRAGMA journal_mode=WAL")
11
11
  @db.run("PRAGMA busy_timeout=5000")
12
- run_migrations
12
+ @migrations_path = File.expand_path("../../../db/migrations", __dir__)
13
13
  end
14
14
 
15
15
  def db
16
16
  @db
17
17
  end
18
18
 
19
+ def migrate!
20
+ dedup_schema_migrations
21
+ run_migrations
22
+ end
23
+
19
24
  private
20
25
 
26
+ def dedup_schema_migrations
27
+ return unless @db.table_exists?(:schema_migrations)
28
+
29
+ cols = @db.schema(:schema_migrations).map(&:first)
30
+ return unless cols.include?(:filename)
31
+
32
+ duplicates = @db.fetch(<<~SQL).all
33
+ SELECT filename, COUNT(*) AS cnt
34
+ FROM schema_migrations
35
+ GROUP BY filename
36
+ HAVING cnt > 1
37
+ SQL
38
+
39
+ duplicates.each do |row|
40
+ @db.fetch(<<~SQL, row[:filename], row[:filename]).all
41
+ DELETE FROM schema_migrations
42
+ WHERE filename = ? AND rowid NOT IN (
43
+ SELECT MIN(rowid) FROM schema_migrations WHERE filename = ?
44
+ )
45
+ SQL
46
+ end
47
+ end
48
+
21
49
  def run_migrations
22
50
  Sequel.extension :migration
23
- path = File.expand_path("../../../db/migrations", __dir__)
24
- Sequel::Migrator.run(@db, path)
51
+ Sequel::Migrator.run(@db, @migrations_path)
25
52
  rescue Sequel::Migrator::Error
26
- GitFit::DB::Rebuild.call(@db, @db.opts[:database], path)
27
- Sequel::Migrator.run(@db, path)
53
+ GitFit::DB::Rebuild.call(@db, @db.opts[:database], @migrations_path)
54
+ Sequel::Migrator.run(@db, @migrations_path)
28
55
  end
29
56
  end
30
57
  end
@@ -13,7 +13,7 @@ module GitFit
13
13
  FileUtils.cp(src, "#{backup}#{ext}") if File.exist?(src)
14
14
  end
15
15
 
16
- tables = db.tables - [:schema_migrations]
16
+ tables = db.tables
17
17
  data = {}
18
18
  tables.each { |t| data[t] = export_table(db, t) }
19
19
 
@@ -60,7 +60,7 @@ module GitFit
60
60
  def init_pending
61
61
  @sources.each do |source|
62
62
  cfg = @config.sync_config(source)
63
- next if cfg.nil? || cfg.empty?
63
+ next if cfg.nil? || (cfg.respond_to?(:empty?) ? cfg.empty? : true)
64
64
  @source_queue << source
65
65
  end
66
66
  @unfinished = @source_queue.size
@@ -1,3 +1,3 @@
1
1
  module GitFit
2
- VERSION = "0.7.4"
2
+ VERSION = "0.7.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-fit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lax