# encoding: utf-8
require 'sequel'
require_relative '../../../services/data-repository/backend/sequel'

# encoding: utf-8
module CartoDB
  module Visualization
    class Migrator
      def initialize(db)
        @db = db
      end

      def migrate(relation=:visualizations)
        @db.create_table(relation.to_sym) do
          String    :id, primary_key: true
          String    :name
          String    :description
          UUID      :map_id, index: true
          String    :active_layer_id
          String    :type
          String    :privacy
          DateTime  :created_at, null: false
          DateTime  :updated_at, null: false
          String    :encrypted_password
          String    :password_salt
          String    :url_options
          UUID      :user_id
          String    :permission_id
          Boolean   :locked
          String    :license
          String    :source
          String    :title
          String    :parent_id
          String    :kind
          String    :prev_id
          String    :next_id
          String    :slide_transition_options
          String    :active_child
        end

        @db.run(%Q{
          ALTER TABLE "#{relation}"
          ADD COLUMN tags text[]
        })
      end

      def drop(relation=:visualizations)
        @db.drop_table(relation.to_sym)
      end
    end
  end
end


# encoding: utf-8
require 'sequel'
require_relative '../../../services/data-repository/backend/sequel'

# encoding: utf-8
module CartoDB
  module Visualization
    class Migrator
      def initialize(db)
        @db = db
      end

      def migrate(relation=:visualizations)
        @db.create_table(relation.to_sym) do
          # TODO: does Clinkr use this and local doesn't?
          UUID      :id, primary_key: true
          String    :name
          String    :description
          UUID      :map_id, index: true
          String    :active_layer_id
          String    :type
          String    :privacy
          DateTime  :created_at, null: false
          DateTime  :updated_at, null: false
          String    :encrypted_password
          String    :password_salt
          String    :url_options
          UUID      :user_id
          String    :permission_id
          Boolean   :locked
          String    :license
          String    :source
          String    :title
          String    :parent_id
          String    :kind
          String    :prev_id
          String    :next_id
          String    :slide_transition_options
          String    :active_child
        end

        @db.run(%Q{
          ALTER TABLE "#{relation}"
          ADD COLUMN tags text[]
        })
      end

      def drop(relation=:visualizations)
        @db.drop_table(relation.to_sym)
      end
    end
  end
end


Test migration visualizations.id type check
Test migration visualizations.id type check
