mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-05 13:20:03 -06:00
feedback
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
"db:migrate:dev": "dotenv -e ../../.env -- sh -c \"pnpm prisma generate && tsx ./src/scripts/apply-migrations.ts\"",
|
||||
"db:create-saml-database:deploy": "env SAML_DATABASE_URL=\"${SAML_DATABASE_URL}\" tsx ./src/scripts/create-saml-database.ts",
|
||||
"db:create-saml-database:dev": "dotenv -e ../../.env -- tsx ./src/scripts/create-saml-database.ts",
|
||||
"db:initial-user-setup:deploy": "env SAML_DATABASE_URL=\"${SAML_DATABASE_URL}\" tsx ./src/scripts/initial-user-setup.ts",
|
||||
"db:initial-user-setup:deploy": "tsx ./src/scripts/initial-user-setup.ts",
|
||||
"db:initial-user-setup:dev": "dotenv -e ../../.env -- tsx ./src/scripts/initial-user-setup.ts",
|
||||
"db:push": "prisma db push --accept-data-loss",
|
||||
"db:setup": "pnpm db:migrate:dev && pnpm db:create-saml-database:dev && pnpm db:initial-user-setup:dev",
|
||||
@@ -29,7 +29,6 @@
|
||||
"@formbricks/logger": "workspace:*",
|
||||
"@paralleldrive/cuid2": "2.2.2",
|
||||
"@prisma/client": "6.7.0",
|
||||
"@prisma/extension-accelerate": "1.3.0",
|
||||
"bcryptjs": "3.0.2",
|
||||
"dotenv-cli": "8.0.0",
|
||||
"zod-openapi": "4.2.4",
|
||||
|
||||
@@ -10,18 +10,21 @@ const { INITIAL_USER_EMAIL, INITIAL_USER_PASSWORD, INITIAL_ORGANIZATION_NAME, IN
|
||||
|
||||
export const isFreshInstance = async (): Promise<boolean> => {
|
||||
try {
|
||||
// Use raw queries to check if instance is fresh
|
||||
const [{ user_count: userCount }] = await prisma.$queryRaw<[{ user_count: number }]>`
|
||||
SELECT COUNT(*)::integer AS user_count FROM "User"
|
||||
`;
|
||||
const [userResult, organizationResult] = await Promise.all([
|
||||
prisma.$queryRaw<[{ user_count: number }]>`
|
||||
SELECT COUNT(*)::integer AS user_count FROM "User"
|
||||
`,
|
||||
prisma.$queryRaw<[{ org_count: number }]>`
|
||||
SELECT COUNT(*)::integer AS org_count FROM "Organization"
|
||||
`,
|
||||
]);
|
||||
|
||||
const [{ org_count: organizationCount }] = await prisma.$queryRaw<[{ org_count: number }]>`
|
||||
SELECT COUNT(*)::integer AS org_count FROM "Organization"
|
||||
`;
|
||||
const userCount = userResult[0].user_count;
|
||||
const organizationCount = organizationResult[0].org_count;
|
||||
|
||||
return userCount === 0 && organizationCount === 0;
|
||||
} catch (error) {
|
||||
logger.error("Error checking if instance is fresh:", error);
|
||||
logger.error(error, "Error checking if instance is fresh:");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -49,7 +52,7 @@ const isValidOrganizationName = (name: string): boolean => {
|
||||
|
||||
const isValidProjectName = (name: string): boolean => {
|
||||
const ZProjectName = z.string().trim().min(1, { message: "Project name cannot be empty" });
|
||||
const parseResult = ZProjectName.safeParse({ name });
|
||||
const parseResult = ZProjectName.safeParse(name);
|
||||
return parseResult.success;
|
||||
};
|
||||
|
||||
@@ -73,6 +76,38 @@ const validateEnvironmentVariables = (): boolean => {
|
||||
return true;
|
||||
};
|
||||
|
||||
const createEnvironment = async (
|
||||
tx: Parameters<Parameters<typeof prisma.$transaction>[0]>[0],
|
||||
type: "development" | "production",
|
||||
projectId: string
|
||||
): Promise<void> => {
|
||||
const now = new Date();
|
||||
const envId = createId();
|
||||
|
||||
await tx.$executeRawUnsafe(
|
||||
`
|
||||
INSERT INTO "Environment" (
|
||||
"id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"type",
|
||||
"projectId",
|
||||
"widgetSetupCompleted",
|
||||
"appSetupCompleted"
|
||||
) VALUES (
|
||||
$1, $2, $3, $4::"EnvironmentType", $5, $6, $7
|
||||
)
|
||||
`,
|
||||
envId,
|
||||
now,
|
||||
now,
|
||||
type,
|
||||
projectId,
|
||||
false,
|
||||
false
|
||||
);
|
||||
};
|
||||
|
||||
const insertUser = async (
|
||||
tx: Parameters<Parameters<typeof prisma.$transaction>[0]>[0],
|
||||
userId: string,
|
||||
@@ -196,8 +231,8 @@ const createInitialUser = async (
|
||||
${now},
|
||||
${projectName},
|
||||
${organizationId},
|
||||
'{}'::jsonb,
|
||||
'{"channel": "link"}'::jsonb,
|
||||
'{"allowStyleOverwrite":true}'::jsonb,
|
||||
'{"channel": "link", "industry":"other"}'::jsonb,
|
||||
7,
|
||||
true,
|
||||
true,
|
||||
@@ -207,51 +242,8 @@ const createInitialUser = async (
|
||||
)
|
||||
`;
|
||||
|
||||
// Create development environment
|
||||
const devEnvironmentId = createId();
|
||||
|
||||
await tx.$executeRaw`
|
||||
INSERT INTO "Environment" (
|
||||
"id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"type",
|
||||
"projectId",
|
||||
"widgetSetupCompleted",
|
||||
"appSetupCompleted"
|
||||
) VALUES (
|
||||
${devEnvironmentId},
|
||||
${now},
|
||||
${now},
|
||||
'development',
|
||||
${projectId},
|
||||
false,
|
||||
false
|
||||
)
|
||||
`;
|
||||
|
||||
// Create production environment
|
||||
const prodEnvironmentId = createId();
|
||||
|
||||
await tx.$executeRaw`
|
||||
INSERT INTO "Environment" (
|
||||
"id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"type",
|
||||
"projectId",
|
||||
"widgetSetupCompleted",
|
||||
"appSetupCompleted"
|
||||
) VALUES (
|
||||
${prodEnvironmentId},
|
||||
${now},
|
||||
${now},
|
||||
'production',
|
||||
${projectId},
|
||||
false,
|
||||
false
|
||||
)
|
||||
`;
|
||||
await createEnvironment(tx, "development", projectId);
|
||||
await createEnvironment(tx, "production", projectId);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -294,7 +286,7 @@ You can now log in with the credentials provided in the environment variables.
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Error during initial environment setup:", error);
|
||||
logger.error("Error during initial environment setup:", error);
|
||||
logger.error(error, "Error during initial environment setup:");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user