ash_sqlite/priv/test_repo/migrations/20240405234211_migrate_resources1.exs
2024-04-05 19:42:16 -04:00

230 lines
No EOL
6.6 KiB
Elixir

defmodule AshSqlite.TestRepo.Migrations.MigrateResources1 do
@moduledoc """
Updates resources based on their most recent snapshots.
This file was autogenerated with `mix ash_sqlite.generate_migrations`
"""
use Ecto.Migration
def up do
create table(:users, primary_key: false) do
add :organization_id,
references(:orgs, column: :id, name: "users_organization_id_fkey", type: :uuid)
add :is_active, :boolean
add :id, :uuid, null: false, primary_key: true
end
create table(:profile, primary_key: false) do
add :author_id,
references(:authors, column: :id, name: "profile_author_id_fkey", type: :uuid)
add :description, :text
add :id, :uuid, null: false, primary_key: true
end
create table(:posts, primary_key: false) do
add :author_id, references(:authors, column: :id, name: "posts_author_id_fkey", type: :uuid)
add :organization_id,
references(:orgs, column: :id, name: "posts_organization_id_fkey", type: :uuid)
add :updated_at, :utc_datetime_usec, null: false
add :created_at, :utc_datetime_usec, null: false
add :uniq_custom_two, :text
add :uniq_custom_one, :text
add :uniq_two, :text
add :uniq_one, :text
add :stuff, :map
add :status_enum, :status
add :status, :text
add :decimal, :decimal
add :price, :bigint
add :type, :text
add :category, :citext
add :public, :boolean
add :score, :bigint
add :title, :text
add :id, :uuid, null: false, primary_key: true
end
create table(:post_views, primary_key: false) do
add :post_id, :uuid, null: false
add :browser, :text
add :time, :utc_datetime_usec, null: false
end
create table(:post_ratings, primary_key: false) do
add :resource_id,
references(:posts, column: :id, name: "post_ratings_resource_id_fkey", type: :uuid)
add :score, :bigint
add :id, :uuid, null: false, primary_key: true
end
create table(:post_links, primary_key: false) do
add :destination_post_id,
references(:posts,
column: :id,
name: "post_links_destination_post_id_fkey",
type: :uuid
),
primary_key: true,
null: false
add :source_post_id,
references(:posts, column: :id, name: "post_links_source_post_id_fkey", type: :uuid),
primary_key: true,
null: false
add :state, :text
end
create unique_index(:post_links, [:source_post_id, :destination_post_id],
name: "post_links_unique_link_index"
)
create table(:orgs, primary_key: false) do
add :name, :text
add :id, :uuid, null: false, primary_key: true
end
create table(:managers, primary_key: false) do
add :organization_id,
references(:orgs, column: :id, name: "managers_organization_id_fkey", type: :uuid)
add :role, :text
add :must_be_present, :text, null: false
add :code, :text, null: false
add :name, :text
add :id, :uuid, null: false, primary_key: true
end
create unique_index(:managers, [:code], name: "managers_uniq_code_index")
create table(:integer_posts, primary_key: false) do
add :title, :text
add :id, :bigserial, null: false, primary_key: true
end
create table(:comments, primary_key: false) do
add :author_id,
references(:authors, column: :id, name: "comments_author_id_fkey", type: :uuid)
add :post_id,
references(:posts,
column: :id,
name: "special_name_fkey",
type: :uuid,
on_delete: :delete_all,
on_update: :update_all
)
add :created_at, :utc_datetime_usec, null: false
add :arbitrary_timestamp, :utc_datetime_usec
add :likes, :bigint
add :title, :text
add :id, :uuid, null: false, primary_key: true
end
create table(:comment_ratings, primary_key: false) do
add :resource_id,
references(:comments,
column: :id,
name: "comment_ratings_resource_id_fkey",
type: :uuid
)
add :score, :bigint
add :id, :uuid, null: false, primary_key: true
end
create table(:authors, primary_key: false) do
add :badges, {:array, :text}
add :bio, :map
add :last_name, :text
add :first_name, :text
add :id, :uuid, null: false, primary_key: true
end
create index(:posts, ["uniq_custom_one", "uniq_custom_two"], unique: true)
create unique_index(:posts, [:uniq_one, :uniq_two],
where: "type = 'sponsored'",
name: "posts_uniq_one_and_two_index"
)
create table(:accounts, primary_key: false) do
add :user_id, references(:users, column: :id, name: "accounts_user_id_fkey", type: :uuid)
add :is_active, :boolean
add :id, :uuid, null: false, primary_key: true
end
end
def down do
drop constraint(:accounts, "accounts_user_id_fkey")
drop table(:accounts)
drop_if_exists unique_index(:posts, [:uniq_one, :uniq_two],
name: "posts_uniq_one_and_two_index"
)
drop_if_exists index(:posts, ["uniq_custom_one", "uniq_custom_two"],
name: "posts_uniq_custom_one_uniq_custom_two_index"
)
drop table(:authors)
drop constraint(:comment_ratings, "comment_ratings_resource_id_fkey")
drop table(:comment_ratings)
drop constraint(:comments, "special_name_fkey")
drop constraint(:comments, "comments_author_id_fkey")
drop table(:comments)
drop table(:integer_posts)
drop_if_exists unique_index(:managers, [:code], name: "managers_uniq_code_index")
drop constraint(:managers, "managers_organization_id_fkey")
drop table(:managers)
drop table(:orgs)
drop_if_exists unique_index(:post_links, [:source_post_id, :destination_post_id],
name: "post_links_unique_link_index"
)
drop constraint(:post_links, "post_links_source_post_id_fkey")
drop constraint(:post_links, "post_links_destination_post_id_fkey")
drop table(:post_links)
drop constraint(:post_ratings, "post_ratings_resource_id_fkey")
drop table(:post_ratings)
drop table(:post_views)
drop constraint(:posts, "posts_organization_id_fkey")
drop constraint(:posts, "posts_author_id_fkey")
drop table(:posts)
drop constraint(:profile, "profile_author_id_fkey")
drop table(:profile)
drop constraint(:users, "users_organization_id_fkey")
drop table(:users)
end
end