Files
ubicloud/migrate/20230117_tables.rb
Enes Cakir 02c8a89c29 Switch TimestampMigrator from IntegerMigrator
IntegerMigrator doesn't allow duplicate migrations (1_foo, 1_bar).
Requires manual renaming for simultaneous migrations.

Here's comparison in detail:
https://sequel.jeremyevans.net/rdoc/files/doc/migration_rdoc.html#label-Two+separate+migrators

The TimestampMigrator will be used if any filename in the migrations
directory has a version greater than 20000101.

IntegerMigrator keeps version information at scheme_info table with an
integer. But TimestampMigrator keeps version information at
scheme_migrations tables with all filenames.

It's not backward compatible. You need to reset your database or create
and fill scheme_migrations table manually, then drop scheme_info table.
2023-07-05 11:15:03 -07:00

46 lines
1.6 KiB
Ruby

# frozen_string_literal: true
Sequel.migration do
change do
create_enum(:allocation_state, %w[unprepared accepting draining])
create_table(:strand) do
column :id, :uuid, primary_key: true, default: Sequel.lit("gen_random_uuid()")
foreign_key :parent_id, :strand, type: :uuid
column :schedule, :timestamptz, null: false, default: Sequel.lit("now()")
column :lease, :timestamptz
column :prog, :text, collate: '"C"', null: false
column :label, :text, collate: '"C"', null: false
column :stack, :jsonb, null: false, default: "[]"
column :exitval, :jsonb
column :retval, :jsonb
end
create_table(:semaphore) do
column :id, :uuid, primary_key: true, default: Sequel.lit("gen_random_uuid()")
foreign_key :strand_id, :strand, type: :uuid, null: false
column :name, :text, collate: '"C"', null: false
end
create_table(:sshable) do
column :id, :uuid, primary_key: true, default: Sequel.lit("gen_random_uuid()")
column :host, :text, collate: '"C"', null: false, unique: true
column :private_key, :text, collate: '"C"'
end
create_table(:vm_host) do
foreign_key :id, :sshable, type: :uuid, primary_key: true
column :allocation_state, :allocation_state, default: "unprepared", null: false
column :ip6, :inet, unique: true
column :net6, :cidr, unique: true
end
create_table(:vm) do
column :id, :uuid, primary_key: true, default: Sequel.lit("gen_random_uuid()")
column :ephemeral_net6, :cidr, unique: true
foreign_key :vm_host_id, :vm_host, type: :uuid
end
end
end