WIP member and properties
This commit is contained in:
parent
2116ee1e91
commit
45fc52d6fb
10 changed files with 446 additions and 1 deletions
63
priv/repo/migrations/20250507171618_initial_migration.exs
Normal file
63
priv/repo/migrations/20250507171618_initial_migration.exs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
defmodule Mv.Repo.Migrations.InitialMigration do
|
||||
@moduledoc """
|
||||
Updates resources based on their most recent snapshots.
|
||||
|
||||
This file was autogenerated with `mix ash_postgres.generate_migrations`
|
||||
"""
|
||||
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
create table(:property_types, primary_key: false) do
|
||||
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
|
||||
add :name, :text, null: false
|
||||
add :type, :text, null: false
|
||||
add :description, :text
|
||||
add :immutable, :boolean, null: false, default: false
|
||||
add :required, :boolean, null: false, default: false
|
||||
end
|
||||
|
||||
create unique_index(:property_types, [:name], name: "property_types_unique_name_index")
|
||||
|
||||
create table(:members, primary_key: false) do
|
||||
add :id, :uuid, null: false, default: fragment("uuid_generate_v7()"), primary_key: true
|
||||
end
|
||||
|
||||
create table(:attribute, primary_key: false) do
|
||||
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
|
||||
add :value, :text
|
||||
|
||||
add :member_id,
|
||||
references(:members,
|
||||
column: :id,
|
||||
name: "attribute_member_id_fkey",
|
||||
type: :uuid,
|
||||
prefix: "public"
|
||||
)
|
||||
|
||||
add :property_type_id,
|
||||
references(:property_types,
|
||||
column: :id,
|
||||
name: "attribute_property_type_id_fkey",
|
||||
type: :uuid,
|
||||
prefix: "public"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
drop constraint(:attribute, "attribute_member_id_fkey")
|
||||
|
||||
drop constraint(:attribute, "attribute_property_type_id_fkey")
|
||||
|
||||
drop table(:attribute)
|
||||
|
||||
drop table(:members)
|
||||
|
||||
drop_if_exists unique_index(:property_types, [:name],
|
||||
name: "property_types_unique_name_index"
|
||||
)
|
||||
|
||||
drop table(:property_types)
|
||||
end
|
||||
end
|
||||
|
|
@ -9,3 +9,31 @@
|
|||
#
|
||||
# We recommend using the bang functions (`insert!`, `update!`
|
||||
# and so on) as they will fail if something goes wrong.
|
||||
|
||||
alias Mv.Membership
|
||||
|
||||
for attrs <- [
|
||||
%{
|
||||
name: "Vorname",
|
||||
type: "string",
|
||||
description: "Vorname des Mitglieds",
|
||||
immutable: true,
|
||||
required: true
|
||||
},
|
||||
%{
|
||||
name: "Email",
|
||||
type: "string",
|
||||
description: "Email-Adresse des Mitglieds",
|
||||
immutable: true,
|
||||
required: true
|
||||
}
|
||||
] do
|
||||
# upsert?: true sorgt dafür, dass bei bestehendem Namen kein Fehler,
|
||||
# sondern ein Update (hier effektiv No-Op) ausgeführt wird
|
||||
{:ok, _} =
|
||||
Membership.create_property_type(
|
||||
attrs,
|
||||
upsert?: true,
|
||||
upsert_identity: :unique_name
|
||||
)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue