45 lines
1.4 KiB
Elixir
45 lines
1.4 KiB
Elixir
defmodule Nulla.Repo.Migrations.CreateInstanceSettings do
|
|
use Ecto.Migration
|
|
|
|
def change do
|
|
create table(:instance_settings, primary_key: false) do
|
|
add :id, :integer, primary_key: true
|
|
add :name, :string, default: "Nulla", null: false
|
|
add :description, :text, default: "Freedom Social Network", null: false
|
|
add :registration, :boolean, default: false, null: false
|
|
add :max_characters, :integer, default: 5000, null: false
|
|
add :max_upload_size, :integer, default: 50, null: false
|
|
add :api_limit, :integer, default: 100, null: false
|
|
add :public_key, :text
|
|
add :private_key, :text
|
|
|
|
timestamps()
|
|
end
|
|
|
|
execute "ALTER TABLE instance_settings ADD CONSTRAINT single_row CHECK (id = 1);"
|
|
|
|
flush()
|
|
|
|
execute(fn ->
|
|
{public_key, private_key} = Nulla.KeyGen.gen()
|
|
now = DateTime.utc_now()
|
|
|
|
esc = fn str -> "'#{String.replace(str, "'", "''")}'" end
|
|
|
|
sql = """
|
|
INSERT INTO instance_settings (
|
|
id, name, description, registration,
|
|
max_characters, max_upload_size, api_limit,
|
|
public_key, private_key, inserted_at, updated_at
|
|
) VALUES (
|
|
1, 'Nulla', 'Freedom Social Network', false,
|
|
5000, 50, 100,
|
|
#{esc.(public_key)}, #{esc.(private_key)},
|
|
'#{now}', '#{now}'
|
|
)
|
|
"""
|
|
|
|
Ecto.Adapters.SQL.query!(Nulla.Repo, sql, [])
|
|
end)
|
|
end
|
|
end
|