class Vcs4sql::Sqlite::Migration

Public Class Methods

new(file) click to toggle source
# File lib/vcs4sql/sqlite/migration.rb, line 41
def initialize(file)
  FileUtils.mkdir_p File.dirname(file)
  @conn = SQLite3::Database.new file
  @conn.results_as_hash = true
end

Public Instance Methods

upgrade(home, testdata=false) click to toggle source

@param home @param testdata

# File lib/vcs4sql/sqlite/migration.rb, line 49
def upgrade(home, testdata=false)
  install_vcs4sql
  existing = Applied.new @conn
  expected = Expected.new home, testdata
  if existing.empty?
    expected.apply_all @conn
  else
    expected.apply_mismatch existing, @conn
  end
end

Private Instance Methods

install_vcs4sql() click to toggle source
# File lib/vcs4sql/sqlite/migration.rb, line 62
      def install_vcs4sql
        # @todo #/DEV Lock the upgrade procedure in order to avoid the cases
        #  when multiple processes are going to modify/upgrade the same database
        #  schema. No concurrent upgrades is allowed so far.
        @conn.execute_batch2 <<~SQL
          create table if not exists changelog (
              id        integer primary key autoincrement,
              file      text not null,
              applied   timestamp default current_timestamp,
              version   integer unique not null,
              md5sum    text not null,
              sql       text not null
          );
          create table if not exists changeloglock (
              id text primary key,
              locked integer,
              lockedby text
          );
        SQL
      end