次のスキーマがあるとします。
Table "public.users"
Column | Type | Modifiers
----------------------+--------------------------+------------------------------------------------------------
uuid | uuid | not null default uuid_generate_v4()
email | character varying(254) | not null
name | text | not null
created_at | timestamp with time zone | not null default now()
Table "public.users_projects"
Column | Type | Modifiers
-----------------+--------------------------+--------------------------------------------
project_uuid | uuid | not null
user_uuid | uuid | not null
invitation_uuid | uuid |
membership_type | membership_type | not null default 'member'::membership_type
created_at | timestamp with time zone | not null default now()
Table "public.projects"
Column | Type | Modifiers
------------+--------------------------+-------------------------------------
uuid | uuid | not null default uuid_generate_v4()
name | character varying(100) | not null
created_at | timestamp with time zone | not null default now()
Table "public.invitations"
Column | Type | Modifiers
-----------------+--------------------------+--------------------------------------------
uuid | uuid | not null default uuid_generate_v4()
email | character varying(254) | not null
target_type | character varying(50) | not null
target_uuid | uuid | not null
membership_type | membership_type | not null default 'member'::membership_type
token | character varying(32) | not null default md5((random())::text)
creator_uuid | uuid | not null
列挙型もありCREATE TYPE membership_type AS ENUM ('guest', 'member', 'manager', 'owner');
ます。
manager
トリガーを使用して、少なくとも結合テーブルにメンバーシップ タイプがなければ、ユーザーがリソースへの招待を作成できないことを確認できるかどうか疑問に思っています。
私の主な質問は次のとおりです。
- 行が挿入される「前」にトリガーを使用できますか?
CREATE TRIGGER check_authorisation BEFORE INSERT OR UPDATE ON invitations FOR EACH ROW EXECUTE PROCEDURE check_authorisation();
- データベース接続がダウンしているなどの理由で単に失敗するのに対して、エラー メッセージでどれだけの情報を返すことができますか?
- これは健全なアプローチですか?私は Web アプリケーション開発者として、これがアプリケーション コードでチェックされる環境に慣れていますが、2 つのアプリケーション (Golang と Ruby) で共有されるデータベースに取り組んでいます。
REFERENCES
どうにかして多相フィールド (target_type
、 )に a を実装できますtarget_uuid
か?