mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Minor improvements on commits code quality
This commit is contained in:
@@ -115,26 +115,21 @@ export async function down(knex: Knex): Promise<void> {
|
||||
const hasFolderTreeCheckpointTable = await knex.schema.hasTable(TableName.FolderTreeCheckpoint);
|
||||
const hasFolderCheckpointTable = await knex.schema.hasTable(TableName.FolderCheckpoint);
|
||||
|
||||
if (hasFolderCheckpointResourcesTable) {
|
||||
await dropOnUpdateTrigger(knex, TableName.FolderCheckpointResources);
|
||||
await knex.schema.dropTableIfExists(TableName.FolderCheckpointResources);
|
||||
}
|
||||
|
||||
if (hasFolderTreeCheckpointResourcesTable) {
|
||||
await dropOnUpdateTrigger(knex, TableName.FolderTreeCheckpointResources);
|
||||
await knex.schema.dropTableIfExists(TableName.FolderTreeCheckpointResources);
|
||||
}
|
||||
|
||||
if (hasFolderTreeCheckpointTable) {
|
||||
await dropOnUpdateTrigger(knex, TableName.FolderTreeCheckpoint);
|
||||
await knex.schema.dropTableIfExists(TableName.FolderTreeCheckpoint);
|
||||
}
|
||||
|
||||
if (hasFolderCheckpointResourcesTable) {
|
||||
await dropOnUpdateTrigger(knex, TableName.FolderCheckpointResources);
|
||||
await knex.schema.dropTableIfExists(TableName.FolderCheckpointResources);
|
||||
}
|
||||
|
||||
if (hasFolderTreeCheckpointTable) {
|
||||
await dropOnUpdateTrigger(knex, TableName.FolderTreeCheckpoint);
|
||||
await knex.schema.dropTableIfExists(TableName.FolderTreeCheckpoint);
|
||||
}
|
||||
|
||||
if (hasFolderCheckpointTable) {
|
||||
await dropOnUpdateTrigger(knex, TableName.FolderCheckpoint);
|
||||
await knex.schema.dropTableIfExists(TableName.FolderCheckpoint);
|
||||
|
||||
@@ -943,6 +943,9 @@ export const secretRotationV2ServiceFactory = ({
|
||||
secretVersionDAL: secretVersionV2BridgeDAL,
|
||||
secretVersionTagDAL: secretVersionTagV2BridgeDAL,
|
||||
folderCommitService,
|
||||
actor: {
|
||||
type: ActorType.PLATFORM
|
||||
},
|
||||
secretTagDAL,
|
||||
resourceMetadataDAL
|
||||
});
|
||||
|
||||
@@ -347,7 +347,7 @@ export const secretRotationQueueFactory = ({
|
||||
actor: {
|
||||
type: ActorType.PLATFORM
|
||||
},
|
||||
message: "Secret rotation",
|
||||
message: "Changed by Secret rotation",
|
||||
folderId: secretVersions[0].folderId,
|
||||
changes: secretVersions.map((sv) => ({
|
||||
type: "add",
|
||||
|
||||
@@ -623,7 +623,7 @@ export const importDataIntoInfisicalFn = async ({
|
||||
id: actorId
|
||||
}
|
||||
},
|
||||
message: "External migration",
|
||||
message: "Changed by external migration",
|
||||
folderId: parentEnv.rootFolderId,
|
||||
changes: [
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Knex } from "knex";
|
||||
import { TDbClient } from "@app/db";
|
||||
import { TableName, TFolderCheckpoints } from "@app/db/schemas";
|
||||
import { DatabaseError } from "@app/lib/errors";
|
||||
import { ormify, selectAllTableCols } from "@app/lib/knex";
|
||||
import { buildFindFilter, ormify, selectAllTableCols } from "@app/lib/knex";
|
||||
|
||||
export type TFolderCheckpointDALFactory = ReturnType<typeof folderCheckpointDALFactory>;
|
||||
|
||||
@@ -34,7 +34,8 @@ export const folderCheckpointDALFactory = (db: TDbClient) => {
|
||||
try {
|
||||
let query = (tx || db.replicaNode())(TableName.FolderCheckpoint)
|
||||
.join(TableName.FolderCommit, `${TableName.FolderCheckpoint}.folderCommitId`, `${TableName.FolderCommit}.id`)
|
||||
.where({ folderId })
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
.where(buildFindFilter({ folderId }, TableName.FolderCommit))
|
||||
.select(selectAllTableCols(TableName.FolderCheckpoint))
|
||||
.select(
|
||||
db.ref("actorMetadata").withSchema(TableName.FolderCommit),
|
||||
@@ -60,7 +61,8 @@ export const folderCheckpointDALFactory = (db: TDbClient) => {
|
||||
try {
|
||||
const doc = await (tx || db.replicaNode())(TableName.FolderCheckpoint)
|
||||
.join(TableName.FolderCommit, `${TableName.FolderCheckpoint}.folderCommitId`, `${TableName.FolderCommit}.id`)
|
||||
.where({ folderId })
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
.where(buildFindFilter({ folderId }, TableName.FolderCommit))
|
||||
.select(selectAllTableCols(TableName.FolderCheckpoint))
|
||||
.select(
|
||||
db.ref("actorMetadata").withSchema(TableName.FolderCommit),
|
||||
|
||||
@@ -13,10 +13,10 @@ export const folderCommitDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findByFolderId = async (folderId: string, tx?: Knex): Promise<TFolderCommits[]> => {
|
||||
try {
|
||||
const docs = await (tx || db.replicaNode())<TFolderCommits>(TableName.FolderCommit)
|
||||
const docs = await (tx || db.replicaNode())(TableName.FolderCommit)
|
||||
.where({ folderId })
|
||||
.select(selectAllTableCols(TableName.FolderCommit))
|
||||
.orderBy("date", "desc");
|
||||
.orderBy("createdAt", "desc");
|
||||
return docs;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "FindByFolderId" });
|
||||
@@ -25,7 +25,7 @@ export const folderCommitDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findById = async (id: string, tx?: Knex): Promise<TFolderCommits | undefined> => {
|
||||
try {
|
||||
const doc = await (tx || db.replicaNode())<TFolderCommits>(TableName.FolderCommit)
|
||||
const doc = await (tx || db.replicaNode())(TableName.FolderCommit)
|
||||
.where({ id })
|
||||
.select(selectAllTableCols(TableName.FolderCommit))
|
||||
.first();
|
||||
@@ -37,10 +37,10 @@ export const folderCommitDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findLatestCommit = async (folderId: string, tx?: Knex): Promise<TFolderCommits | undefined> => {
|
||||
try {
|
||||
const doc = await (tx || db.replicaNode())<TFolderCommits>(TableName.FolderCommit)
|
||||
const doc = await (tx || db.replicaNode())(TableName.FolderCommit)
|
||||
.where({ folderId })
|
||||
.select(selectAllTableCols(TableName.FolderCommit))
|
||||
.orderBy("date", "desc")
|
||||
.orderBy("createdAt", "desc")
|
||||
.first();
|
||||
return doc;
|
||||
} catch (error) {
|
||||
|
||||
@@ -77,18 +77,15 @@ export const folderCommitServiceFactory = ({
|
||||
},
|
||||
tx
|
||||
);
|
||||
for (const change of data.changes) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await folderCommitChangesDAL.create(
|
||||
{
|
||||
folderCommitId: newCommit.id,
|
||||
changeType: change.type,
|
||||
secretVersionId: change.secretVersionId,
|
||||
folderVersionId: change.folderVersionId
|
||||
},
|
||||
tx
|
||||
);
|
||||
}
|
||||
await folderCommitChangesDAL.insertMany(
|
||||
data.changes.map((change) => ({
|
||||
folderCommitId: newCommit.id,
|
||||
changeType: change.type,
|
||||
secretVersionId: change.secretVersionId,
|
||||
folderVersionId: change.folderVersionId
|
||||
})),
|
||||
tx
|
||||
);
|
||||
|
||||
return newCommit;
|
||||
} catch (error) {
|
||||
@@ -96,7 +93,7 @@ export const folderCommitServiceFactory = ({
|
||||
}
|
||||
};
|
||||
|
||||
// Add a change to a commit and trigger checkpoints as needed
|
||||
// Add a change to an existing commit
|
||||
const addCommitChange = async (data: TCommitChangeDTO, tx?: Knex) => {
|
||||
try {
|
||||
if (!data.secretVersionId && !data.folderVersionId) {
|
||||
|
||||
@@ -182,7 +182,7 @@ export type TFnSecretBulkInsert = {
|
||||
folderCommitService: Pick<TFolderCommitServiceFactory, "createCommit">;
|
||||
actor?: {
|
||||
type: string;
|
||||
actorId: string;
|
||||
actorId?: string;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -211,7 +211,7 @@ export type TFnSecretBulkUpdate = {
|
||||
folderCommitService: Pick<TFolderCommitServiceFactory, "createCommit">;
|
||||
actor?: {
|
||||
type: string;
|
||||
actorId: string;
|
||||
actorId?: string;
|
||||
};
|
||||
tx?: Knex;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user