48 lines
1.5 KiB
Elixir
48 lines
1.5 KiB
Elixir
defmodule Nulla.Repo.Migrations.CreateInstanceSettings do
|
|
use Ecto.Migration
|
|
|
|
def change do
|
|
create table(:instance_settings) do
|
|
add :name, :string, default: "Nulla", null: false
|
|
add :description, :text, default: "Freedom Social Network", null: false
|
|
add :domain, :string, default: "localhost", 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_offset, :integer, default: 100, null: false
|
|
add :public_key, :text
|
|
add :private_key, :text
|
|
|
|
timestamps()
|
|
end
|
|
|
|
flush()
|
|
|
|
execute(fn ->
|
|
{public_key, private_key} = Nulla.KeyGen.generate_keys()
|
|
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
|
|
|
domain =
|
|
Application.get_env(:nulla, NullaWeb.Endpoint, [])
|
|
|> Keyword.get(:url, [])
|
|
|> Keyword.get(:host, "localhost")
|
|
|
|
esc = fn str -> "'#{String.replace(str, "'", "''")}'" end
|
|
|
|
sql = """
|
|
INSERT INTO instance_settings (
|
|
name, description, domain, registration,
|
|
max_characters, max_upload_size, api_offset,
|
|
public_key, private_key, inserted_at, updated_at
|
|
) VALUES (
|
|
'Nulla', 'Freedom Social Network', '#{domain}', false,
|
|
5000, 50, 100,
|
|
#{esc.(public_key)}, #{esc.(private_key)},
|
|
'#{now}', '#{now}'
|
|
)
|
|
"""
|
|
|
|
Ecto.Adapters.SQL.query!(Nulla.Repo, sql, [])
|
|
end)
|
|
end
|
|
end
|