Sha256: 0accd8e1af1ecae28bbd7203c38bf93dcfe03fa6c56d0f95d35000c947433e23

Contents?: true

Size: 1020 Bytes

Versions: 12

Compression:

Stored size: 1020 Bytes

Contents

#!/usr/bin/env ruby

require_relative '../builder/builder.rb'

module Prick::SubCommand
  def self.snapshot(
      database, username,
      builddir: Prick.state.schema_dir)

    conn = Prick.state.connection
    builder = Prick::Build::Builder.new(conn, builddir)
    pool = builder.pool
    schemas = pool.refresh_schemas

    # Clear snapshots table
    conn.exec "delete from prick.snapshots"

    # Fill it again
    records = []
    for schema in schemas
      conn.schema.list_tables(schema).each { |table|
        max_id = conn.value "select max(id) from #{schema}.#{table}"
        records << { schema_name: schema, table_name: table, max_id: max_id}
      }
    end
    conn.insert("prick", "snapshots", records)

    # Patch fox state file
    state = YAML.load(IO.read(Prick.state.fox_state_file))
    for record in records
      state[:ids][record[:schema_name] + '.' + record[:table_name]] = record[:max_id] if record[:max_id]
    end
    IO.write(Prick.state.fox_state_file, YAML.dump(state))
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
prick-0.45.0 lib/prick/subcommand/prick-snapshot.rb
prick-0.44.0 lib/prick/subcommand/prick-snapshot.rb
prick-0.43.1 lib/prick/subcommand/prick-snapshot.rb
prick-0.43.0 lib/prick/subcommand/prick-snapshot.rb
prick-0.42.1 lib/prick/subcommand/prick-snapshot.rb
prick-0.42.0 lib/prick/subcommand/prick-snapshot.rb
prick-0.41.0 lib/prick/subcommand/prick-snapshot.rb
prick-0.40.3 lib/prick/subcommand/prick-snapshot.rb
prick-0.40.2 lib/prick/subcommand/prick-snapshot.rb
prick-0.40.1 lib/prick/subcommand/prick-snapshot.rb
prick-0.40.0 lib/prick/subcommand/prick-snapshot.rb
prick-0.39.13 lib/prick/subcommand/prick-snapshot.rb