import { userTable } from "../user/user.sql.js";
import { pgTable, unique, varchar } from "drizzle-orm/pg-core";
import { id, timestamps, ulid } from "../drizzle/types.js";

export const orgTable = pgTable(
  "organisations",
  {
    ...id,
    ...timestamps,
    ownerID: ulid("owner_id")
      .references(() => userTable.id, {
        onDelete: "cascade",
      })
      .notNull(),
    name: varchar("name", { length: 255 }).notNull(),
    slug: varchar("slug", { length: 255 }).notNull(),
  },
  (org) => [unique("idx_organisation_slug").on(org.slug)],
);
