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.29.2 lib/prick/subcommand/prick-migrate.rb
prick-0.29.1 lib/prick/subcommand/prick-migrate.rb
prick-0.29.0 lib/subcommand/prick-migrate.rb
prick-0.28.1 lib/subcommand/prick-migrate.rb
prick-0.28.0 lib/subcommand/prick-migrate.rb
prick-0.27.2 lib/subcommand/prick-migrate.rb
prick-0.27.1 lib/subcommand/prick-migrate.rb
prick-0.27.0 lib/subcommand/prick-migrate.rb
prick-0.26.0 lib/subcommand/prick-migrate.rb
prick-0.25.2 lib/subcommand/prick-migrate.rb
prick-0.25.1 lib/subcommand/prick-migrate.rb
prick-0.25.0 lib/subcommand/prick-migrate.rb
prick-0.24.0 lib/subcommand/prick-migrate.rb
prick-0.23.0 lib/subcommand/prick-migrate.rb
prick-0.22.0 lib/subcommand/prick-migrate.rb
prick-0.21.3 lib/subcommand/prick-migrate.rb
prick-0.21.2 lib/subcommand/prick-migrate.rb
prick-0.21.1 lib/subcommand/prick-migrate.rb
prick-0.21.0 lib/subcommand/prick-migrate.rb
prick-0.20.28 lib/subcommand/prick-migrate.rb