cartodb/db/migrate/20161125174333_create_snapshots.rb

34 lines
876 B
Ruby
Raw Permalink Normal View History

2020-06-15 10:58:47 +08:00
require 'carto/db/migration_helper'
include Carto::Db::MigrationHelper
migration(
Proc.new do
create_table :snapshots do
Uuid :id, primary_key: true, default: Sequel.lit('uuid_generate_v4()')
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
String :state, null: false, type: 'json', default: '{}'
foreign_key :user_id,
:users,
type: :uuid,
null: false,
on_delete: :cascade
foreign_key :visualization_id,
:visualizations,
type: :uuid,
null: false,
on_delete: :cascade
end
alter_table :snapshots do
add_index [:visualization_id, :user_id]
end
end,
Proc.new do
drop_table :snapshots
end
)