Class: GitFit::DB::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/git_fit/db/cli.rb

Instance Method Summary collapse

Instance Method Details

#checkpointObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/git_fit/db/cli.rb', line 36

def checkpoint
  config = GitFit::Config.new
  conn = GitFit::DB::Connection.new(config.db_path)
  result = conn.checkpoint
  say_status :checkpoint, 'WAL checkpoint complete', :green
  puts "  busy=#{result[:busy]} log=#{result[:log]} checkpointed=#{result[:checkpointed]}"
rescue StandardError => e
  say_status :error, "Checkpoint failed: #{e.message}", :red
  exit(1)
end

#migrateObject



9
10
11
12
13
14
15
16
# File 'lib/git_fit/db/cli.rb', line 9

def migrate
  config = GitFit::Config.new
  conn = GitFit::DB::Connection.new(config.db_path)
  conn.migrate!
  say_status :done, 'Migrations up to date', :green
rescue StandardError => e
  say_status :error, "Migration failed: #{e.message}", :red
end

#schemaObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/git_fit/db/cli.rb', line 20

def schema
  require 'digest'
  db = Sequel.sqlite
  Sequel.extension :migration
  dir = File.expand_path('../../../db/migrations', __dir__)
  Sequel::Migrator.run(db, dir)
  ddl = db.fetch('SELECT sql FROM sqlite_master WHERE sql IS NOT NULL ORDER BY name')
        .map(:sql).join("\n") + "\n"
  if options[:hash]
    puts Digest::SHA256.hexdigest(ddl)
  else
    print ddl
  end
end