First
[anni] / priv / repo / migrations / 20201012173004_refactor_deactivated_user_field.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Repo.Migrations.RefactorDeactivatedUserField do
6   use Ecto.Migration
7
8   def up do
9     # Flip the values before we change the meaning of the column
10     execute("UPDATE users SET deactivated = NOT deactivated;")
11     execute("ALTER TABLE users RENAME COLUMN deactivated TO is_active;")
12     execute("ALTER TABLE users ALTER COLUMN is_active SET DEFAULT true;")
13     execute("ALTER INDEX users_deactivated_index RENAME TO users_is_active_index;")
14   end
15
16   def down do
17     execute("UPDATE users SET is_active = NOT is_active;")
18     execute("ALTER TABLE users RENAME COLUMN is_active TO deactivated;")
19     execute("ALTER TABLE users ALTER COLUMN deactivated SET DEFAULT false;")
20     execute("ALTER INDEX users_is_active_index RENAME TO users_deactivated_index;")
21   end
22 end