Sha256: 92a388ad862b016f394d03ee2ae7d1ef5026a47ab63605efba1efdb9db795d7c

Contents?: true

Size: 1.25 KB

Versions: 45

Compression:

Stored size: 1.25 KB

Contents

module Prick
  module SubCommand
#   def self.migrate(database, username, file) TODO
    def self.migrate(database, username, file: nil)
      PgConn.new(database, username) { |conn|
        conn.schema.exist_relation? "prick", "versions" or 
            raise Prick::Fail, "Can't read version from database"

        from_version = PrickVersion.new(conn.value "select version from prick.versions") or
            raise Prick::Fail, "Illegal version in table prick.versions"

        if file
          conn.transaction {
            conn.exec File.read(file)
          }
        else
          to_version = Prick.state.version
          from_version != to_version or raise Prick::Fail, "Already up to date"
          from_version < to_version or raise Prick::Fail, "Can't migrate backwards"

          migration_dir = "#{MIGRATION_DIR}/#{from_version}" 
          File.directory? migration_dir or 
              raise Prick::Fail, "Can't migrate from #{from_version} to #{to_version}"

          puts "Migrating from #{from_version} to #{to_version}"

          builder = Prick::Build::Builder.new(conn, migration_dir)
          conn.transaction {
            builder.execute conn
            conn.exec File.read(SCHEMA_VERSION_PATH)
          }
        end
      }
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
prick-0.20.6 lib/subcommand/prick-migrate.rb
prick-0.20.5 lib/subcommand/prick-migrate.rb
prick-0.20.4 lib/subcommand/prick-migrate.rb
prick-0.20.2 lib/subcommand/prick-migrate.rb
prick-0.20.1 lib/subcommand/prick-migrate.rb