mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-04-18 22:09:30 -04:00
* refactor: move migrations to new structure * refactor: convert all findMany to new structure * fix(backups-schedule): missing null matching for last backup status * chore: move root lib to server
36 lines
929 B
TypeScript
36 lines
929 B
TypeScript
import { db } from "~/server/db/db";
|
|
import { organization, type OrganizationMetadata } from "~/server/db/schema";
|
|
import { faker } from "@faker-js/faker";
|
|
|
|
export const TEST_ORG_ID = "test-org-00000001";
|
|
|
|
export const createTestOrganization = async (overrides: Partial<typeof organization.$inferInsert> = {}) => {
|
|
const metadata: OrganizationMetadata = {
|
|
resticPassword: "test-encrypted-restic-password",
|
|
};
|
|
|
|
const org: typeof organization.$inferInsert = {
|
|
id: TEST_ORG_ID,
|
|
name: "Test Organization",
|
|
slug: `test-org-${faker.string.alphanumeric(6)}`,
|
|
createdAt: new Date(),
|
|
metadata,
|
|
...overrides,
|
|
};
|
|
|
|
const existing = await db.query.organization.findFirst({
|
|
where: { id: org.id },
|
|
});
|
|
|
|
if (existing) {
|
|
return existing;
|
|
}
|
|
|
|
const data = await db.insert(organization).values(org).returning();
|
|
return data[0];
|
|
};
|
|
|
|
export const ensureTestOrganization = async () => {
|
|
return createTestOrganization();
|
|
};
|