15a0192e20a8c3eda6ba7592742ac48b15f645af
[anni] / priv / repo / migrations / 20190213185503_change_apps_scopes_to_varchar_array.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.ChangeAppsScopesToVarcharArray do
6   use Ecto.Migration
7
8   @alter_apps_scopes "ALTER TABLE apps ALTER COLUMN scopes"
9
10   def up do
11     execute(
12       "#{@alter_apps_scopes} TYPE varchar(255)[] USING string_to_array(scopes, ',')::varchar(255)[];"
13     )
14
15     execute("#{@alter_apps_scopes} SET DEFAULT ARRAY[]::character varying[];")
16     execute("#{@alter_apps_scopes} SET NOT NULL;")
17   end
18
19   def down do
20     execute("#{@alter_apps_scopes} DROP NOT NULL;")
21     execute("#{@alter_apps_scopes} DROP DEFAULT;")
22
23     execute(
24       "#{@alter_apps_scopes} TYPE varchar(255) USING array_to_string(scopes, ',')::varchar(255);"
25     )
26   end
27 end