Sha256: b035a0a4299d354c7de73227272e9878bdc1b7c7adf02ae377fa258a3779fe18

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

require 'dm-migrations/sql/table'

module SQL
  module Mysql

    def supports_schema_transactions?
      false
    end

    def table(table_name)
      SQL::Mysql::Table.new(self, table_name)
    end

    def recreate_database
      execute "DROP DATABASE #{schema_name}"
      execute "CREATE DATABASE #{schema_name}"
      execute "USE #{schema_name}"
    end

    def supports_serial?
      true
    end

    def table_options
      " ENGINE = InnoDB CHARACTER SET #{character_set} COLLATE #{collation}"
    end

    def property_schema_statement(connection, schema)
      if supports_serial? && schema[:serial]
        statement = "#{schema[:quote_column_name]} SERIAL PRIMARY KEY"
      else
        super
      end
    end

    def change_column_type_statement(name, column)
      "ALTER TABLE #{quote_name(name)} MODIFY COLUMN #{column.to_sql}"
    end

    class Table
      def initialize(adapter, table_name)
        @columns = []
        adapter.table_info(table_name).each do |col_struct|
          @columns << SQL::Mysql::Column.new(col_struct)
        end
      end
    end

    class Column
      def initialize(col_struct)
        @name, @type, @default_value, @primary_key = col_struct.name, col_struct.type, col_struct.dflt_value, col_struct.pk

        @not_null = col_struct.notnull == 0
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dm-migrations-1.1.0 lib/dm-migrations/sql/mysql.rb
dm-migrations-1.1.0.rc3 lib/dm-migrations/sql/mysql.rb