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 +4 -4
- data/lib/git_fit/cli/export.rb +3 -1
- data/lib/git_fit/cli/geo_cli.rb +3 -1
- data/lib/git_fit/cli/import_cli.rb +15 -5
- data/lib/git_fit/cli/sync.rb +1 -1
- data/lib/git_fit/cli.rb +3 -1
- data/lib/git_fit/config.rb +2 -1
- data/lib/git_fit/db/cli.rb +2 -1
- data/lib/git_fit/db/connection.rb +32 -5
- data/lib/git_fit/db/rebuild.rb +1 -1
- data/lib/git_fit/sync/runner.rb +1 -1
- data/lib/git_fit/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: 7c031091e27306d5f66a2754029c00d6047d07945b11f1a45a18332a1d0b0e02
|
|
4
|
+
data.tar.gz: 3fb56126e52afdf6f0d89e4aa54665fee7e9dd2fad37f3f3b36cf8b451f0f0eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed9cce62705d3685fa03d604e4ae3acaaf68e224779ccaec522ad6d3572a9edfbf24180617ac3aadd6458cef63883606c760f6c59180ab9c094da15332d22af3
|
|
7
|
+
data.tar.gz: '06758cbad1a0e60576a6662cc69b29449d98cd5fb24f3b1fd97b3a2b72bc211fbd59bb19add5b54693fecade1e9b756eccb6dcba8ac9b2d7885cc3da03177d65'
|
data/lib/git_fit/cli/export.rb
CHANGED
|
@@ -13,7 +13,9 @@ module GitFit
|
|
|
13
13
|
|
|
14
14
|
def json
|
|
15
15
|
config = git_fit_config
|
|
16
|
-
|
|
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
|
data/lib/git_fit/cli/geo_cli.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
data/lib/git_fit/cli/sync.rb
CHANGED
|
@@ -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
data/lib/git_fit/config.rb
CHANGED
data/lib/git_fit/db/cli.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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],
|
|
27
|
-
Sequel::Migrator.run(@db,
|
|
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
|
data/lib/git_fit/db/rebuild.rb
CHANGED
data/lib/git_fit/sync/runner.rb
CHANGED
|
@@ -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
|
data/lib/git_fit/version.rb
CHANGED