mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 16:52:38 +00:00
Merge branch 'main' into ENG-3506-LDAP
This commit is contained in:
+2
-3
@@ -1,5 +1,6 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { dropConstraintIfExists } from "@app/db/migrations/utils/dropConstraintIfExists";
|
||||
import { TableName } from "@app/db/schemas";
|
||||
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
@@ -13,9 +14,7 @@ export async function up(knex: Knex): Promise<void> {
|
||||
}
|
||||
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable(TableName.AppConnection, (t) => {
|
||||
t.dropUnique(["orgId", "name"]);
|
||||
});
|
||||
await dropConstraintIfExists(TableName.AppConnection, "app_connections_orgid_name_unique", knex);
|
||||
|
||||
await knex.schema.alterTable(TableName.SecretSync, (t) => {
|
||||
t.dropUnique(["projectId", "name"]);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { dropConstraintIfExists } from "@app/db/migrations/utils/dropConstraintIfExists";
|
||||
import { TableName } from "@app/db/schemas";
|
||||
|
||||
const UNIQUE_NAME_ORG_CONNECTION_INDEX = "unique_name_org_app_connection";
|
||||
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
if (await knex.schema.hasTable(TableName.AppConnection)) {
|
||||
// we can't add the constraint back after up since there may be conflicting names so we do if exists
|
||||
await dropConstraintIfExists(TableName.AppConnection, "app_connections_orgid_name_unique", knex);
|
||||
|
||||
if (!(await knex.schema.hasColumn(TableName.AppConnection, "projectId"))) {
|
||||
await knex.schema.alterTable(TableName.AppConnection, (t) => {
|
||||
t.string("projectId").nullable();
|
||||
t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");
|
||||
// unique name for project-level connections
|
||||
t.unique(["name", "projectId", "orgId"]);
|
||||
});
|
||||
|
||||
// unique name for org-level connections
|
||||
await knex.raw(`
|
||||
CREATE UNIQUE INDEX ${UNIQUE_NAME_ORG_CONNECTION_INDEX}
|
||||
ON ${TableName.AppConnection} ("name", "orgId")
|
||||
WHERE "projectId" IS NULL
|
||||
`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
if (await knex.schema.hasTable(TableName.AppConnection)) {
|
||||
if (await knex.schema.hasColumn(TableName.AppConnection, "projectId")) {
|
||||
await knex.schema.alterTable(TableName.AppConnection, (t) => {
|
||||
t.dropUnique(["name", "projectId", "orgId"]);
|
||||
t.dropColumn("projectId");
|
||||
});
|
||||
await dropConstraintIfExists(TableName.AppConnection, UNIQUE_NAME_ORG_CONNECTION_INDEX, knex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,8 @@ export const AppConnectionsSchema = z.object({
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
isPlatformManagedCredentials: z.boolean().default(false).nullable().optional(),
|
||||
gatewayId: z.string().uuid().nullable().optional()
|
||||
gatewayId: z.string().uuid().nullable().optional(),
|
||||
projectId: z.string().nullable().optional()
|
||||
});
|
||||
|
||||
export type TAppConnections = z.infer<typeof AppConnectionsSchema>;
|
||||
|
||||
Reference in New Issue
Block a user