summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20240223165000_create_bookmark_folders.exs
blob: 016916968183ba85065a0987e12af1b03d040631 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Pleroma: A lightweight social networking server
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Repo.Migrations.CreateBookmarkFolders do
  use Ecto.Migration

  def change do
    create_if_not_exists table(:bookmark_folders, primary_key: false) do
      add(:id, :uuid, primary_key: true)
      add(:name, :string, null: false)
      add(:emoji, :string)
      add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))

      timestamps()
    end

    alter table(:bookmarks) do
      add_if_not_exists(
        :folder_id,
        references(:bookmark_folders, type: :uuid, on_delete: :nilify_all)
      )
    end

    create_if_not_exists(unique_index(:bookmark_folders, [:user_id, :name]))
  end
end