Skip to content

Commit

Permalink
enh: add version (superseded | latest) to content frags
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Fontanier committed Nov 15, 2024
1 parent 00db557 commit 41525ae
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions front/lib/resources/content_fragment_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export class ContentFragmentResource extends BaseResource<ContentFragmentModel>
email: this.userContextEmail,
username: this.userContextUsername,
},
contentFragmentId: this.sId,
contentFragmentVersion: this.version,
};
}
}
Expand Down
14 changes: 12 additions & 2 deletions front/lib/resources/storage/models/content_fragment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { SupportedContentFragmentType } from "@dust-tt/types";
import type {
ContentFragmentVersion,
SupportedContentFragmentType,
} from "@dust-tt/types";
import type {
CreationOptional,
ForeignKey,
Expand Down Expand Up @@ -36,6 +39,8 @@ export class ContentFragmentModel extends Model<

declare userId: ForeignKey<User["id"]> | null;
declare fileId: ForeignKey<FileModel["id"]> | null;

declare version: ContentFragmentVersion;
}

ContentFragmentModel.init(
Expand Down Expand Up @@ -91,11 +96,16 @@ ContentFragmentModel.init(
type: DataTypes.STRING,
allowNull: true,
},
version: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: "latest",
},
},
{
modelName: "content_fragment",
sequelize: frontSequelize,
indexes: [{ fields: ["fileId"] }, { fields: ["sId"] }],
indexes: [{ fields: ["fileId"] }, { fields: ["sId", "version"] }],
}
);

Expand Down
11 changes: 11 additions & 0 deletions front/migrations/db/migration_114.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Add version column
ALTER TABLE
"public"."content_fragments"
ADD
COLUMN "version" VARCHAR(255) NOT NULL DEFAULT 'latest';

-- Create the composite index concurrently to avoid locking
CREATE INDEX CONCURRENTLY "content_fragments_s_id_version" ON "content_fragments" ("sId", "version");

-- Drop the old single-column index if it exists
DROP INDEX CONCURRENTLY IF EXISTS "content_fragments_s_id";
4 changes: 4 additions & 0 deletions types/src/front/content_fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export function getSupportedContentFragmentTypeCodec(): t.Mixed {
]);
}

export type ContentFragmentVersion = "superseded" | "latest";

export type ContentFragmentType = {
id: ModelId;
sId: string;
Expand All @@ -49,6 +51,8 @@ export type ContentFragmentType = {
title: string;
contentType: SupportedContentFragmentType;
context: ContentFragmentContextType;
contentFragmentId: string;
contentFragmentVersion: ContentFragmentVersion;
};

export type UploadedContentFragment = {
Expand Down

0 comments on commit 41525ae

Please sign in to comment.