Music streaming on ATProto!
1defmodule Comet.Repo.Migrations.Init do 2 use Ecto.Migration 3 4 defmacrop did_rkey do 5 quote do 6 add :did, references(:identity, column: :did, type: :string), null: false 7 add :rkey, :string, null: false 8 end 9 end 10 11 def change do 12 create table(:identity, primary_key: false) do 13 add :did, :string, primary_key: true, null: false 14 add :handle, :string 15 add :active, :boolean, null: false 16 add :status, :string 17 # TODO: cache of did record? 18 timestamps(inserted_at: :indexed_at, updated_at: false) 19 end 20 21 create table(:profiles) do 22 did_rkey() 23 add :display_name, :string 24 add :description, :string 25 # TODO: as a table? 26 add :description_facets, :map 27 add :avatar, :string 28 add :banner, :string 29 # TODO: as a table? 30 add :featured_items, {:array, :string} 31 add :created_at, :utc_datetime 32 timestamps(inserted_at: :indexed_at, updated_at: false) 33 end 34 35 create unique_index(:profiles, [:did, :rkey]) 36 37 create table(:tracks) do 38 did_rkey() 39 add :title, :string, null: false 40 add :audio, :string, null: false 41 add :image, :string 42 add :description, :string 43 add :description_facets, :map 44 add :explicit, :boolean 45 # TODO: table for easier linking? 46 add :tags, {:array, :string} 47 add :link, :map 48 add :created_at, :utc_datetime, null: false 49 add :released_at, :utc_datetime 50 timestamps(inserted_at: :indexed_at, updated_at: false) 51 end 52 53 create index(:tracks, [:did, :rkey]) 54 55 create table(:playlists) do 56 did_rkey() 57 add :title, :string, null: false 58 add :image, :string 59 add :description, :string 60 add :description_facets, :map 61 add :type, :string, null: false 62 add :tags, {:array, :string} 63 add :link, :map 64 add :created_at, :utc_datetime, null: false 65 timestamps(inserted_at: :indexed_at, updated_at: false) 66 end 67 68 # TODO: probably still can do unique index on this 69 create index(:playlists, [:did, :rkey]) 70 71 create table(:playlist_tracks) do 72 did_rkey() 73 74 add :track_id, references(:tracks), null: false 75 add :playlist_id, references(:playlists), null: false 76 77 add :position, :integer, null: true 78 add :created_at, :utc_datetime, null: false 79 timestamps(inserted_at: :indexed_at, updated_at: false) 80 end 81 82 create index(:playlist_tracks, [:did, :rkey]) 83 # create unique_index() 84 85 create table(:likes) do 86 did_rkey() 87 # add :subject_did, :string, null: false 88 add :subject_id, :binary_id, null: false 89 add :subject_type, :string, null: false 90 add :created_at, :utc_datetime, null: false 91 end 92 93 create index(:likes, [:did, :rkey]) 94 create unique_index(:likes, [:did, :subject_id]) 95 96 create table(:reposts) do 97 did_rkey() 98 # add :subject_did, :string, null: false 99 add :subject_id, :binary_id, null: false 100 add :subject_type, :string, null: false 101 add :created_at, :utc_datetime, null: false 102 end 103 104 create index(:reposts, [:did, :rkey]) 105 create unique_index(:reposts, [:did, :subject_id]) 106 107 create table(:plays) do 108 did_rkey() 109 add :subject, references(:tracks), null: false 110 add :created_at, :utc_datetime, null: false 111 end 112 113 create index(:plays, [:did, :rkey]) 114 115 create table(:comments) do 116 did_rkey() 117 add :text, :string, null: false 118 add :subject_id, :binary_id, null: false 119 add :subject_type, :string, null: false 120 add :reply_id, references(:comments) 121 # add :reply, :string 122 add :langs, {:array, :string} 123 add :facets, :map 124 add :created_at, :utc_datetime, null: false 125 end 126 127 create index(:comments, [:did, :rkey]) 128 end 129end