Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use laravel::db::AnyTransaction;

/// Invitations to an organization, by email or by a login on a forge (ported as today's). `for_user_id` is the
/// account it's for when one existed when it was sent, so it shows on their side; it waits for them to accept.
pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> {
tx.query(
"CREATE TABLE invitations (
id BIGSERIAL PRIMARY KEY,
pid UUID NOT NULL UNIQUE,
organization_id BIGINT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
email TEXT,
forge TEXT,
login TEXT,
role TEXT NOT NULL CHECK (role IN ('admin', 'member', 'read')),
invited_by BIGINT REFERENCES users(id) ON DELETE SET NULL,
accepted_by BIGINT REFERENCES users(id) ON DELETE SET NULL,
accepted_at TIMESTAMPTZ,
for_user_id BIGINT REFERENCES users(id) ON DELETE CASCADE,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CHECK ((email IS NOT NULL) <> (login IS NOT NULL)),
CHECK ((login IS NULL) = (forge IS NULL))
);
CREATE UNIQUE INDEX invitations_pending_email ON invitations (organization_id, lower(email))
WHERE accepted_at IS NULL AND email IS NOT NULL;
CREATE UNIQUE INDEX invitations_pending_login ON invitations (organization_id, forge, lower(login))
WHERE accepted_at IS NULL AND login IS NOT NULL;
CREATE INDEX invitations_for_user ON invitations (for_user_id) WHERE accepted_at IS NULL;",
)
.unprepared()
.await?;
Ok(())
}
Loading
Loading