Skip to content

Commit 41525ae

Browse files
author
Henry Fontanier
committed
enh: add version (superseded | latest) to content frags
1 parent 00db557 commit 41525ae

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

front/lib/resources/content_fragment_resource.ts

+2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ export class ContentFragmentResource extends BaseResource<ContentFragmentModel>
201201
email: this.userContextEmail,
202202
username: this.userContextUsername,
203203
},
204+
contentFragmentId: this.sId,
205+
contentFragmentVersion: this.version,
204206
};
205207
}
206208
}

front/lib/resources/storage/models/content_fragment.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { SupportedContentFragmentType } from "@dust-tt/types";
1+
import type {
2+
ContentFragmentVersion,
3+
SupportedContentFragmentType,
4+
} from "@dust-tt/types";
25
import type {
36
CreationOptional,
47
ForeignKey,
@@ -36,6 +39,8 @@ export class ContentFragmentModel extends Model<
3639

3740
declare userId: ForeignKey<User["id"]> | null;
3841
declare fileId: ForeignKey<FileModel["id"]> | null;
42+
43+
declare version: ContentFragmentVersion;
3944
}
4045

4146
ContentFragmentModel.init(
@@ -91,11 +96,16 @@ ContentFragmentModel.init(
9196
type: DataTypes.STRING,
9297
allowNull: true,
9398
},
99+
version: {
100+
type: DataTypes.STRING,
101+
allowNull: false,
102+
defaultValue: "latest",
103+
},
94104
},
95105
{
96106
modelName: "content_fragment",
97107
sequelize: frontSequelize,
98-
indexes: [{ fields: ["fileId"] }, { fields: ["sId"] }],
108+
indexes: [{ fields: ["fileId"] }, { fields: ["sId", "version"] }],
99109
}
100110
);
101111

front/migrations/db/migration_114.sql

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Add version column
2+
ALTER TABLE
3+
"public"."content_fragments"
4+
ADD
5+
COLUMN "version" VARCHAR(255) NOT NULL DEFAULT 'latest';
6+
7+
-- Create the composite index concurrently to avoid locking
8+
CREATE INDEX CONCURRENTLY "content_fragments_s_id_version" ON "content_fragments" ("sId", "version");
9+
10+
-- Drop the old single-column index if it exists
11+
DROP INDEX CONCURRENTLY IF EXISTS "content_fragments_s_id";

types/src/front/content_fragment.ts

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export function getSupportedContentFragmentTypeCodec(): t.Mixed {
3535
]);
3636
}
3737

38+
export type ContentFragmentVersion = "superseded" | "latest";
39+
3840
export type ContentFragmentType = {
3941
id: ModelId;
4042
sId: string;
@@ -49,6 +51,8 @@ export type ContentFragmentType = {
4951
title: string;
5052
contentType: SupportedContentFragmentType;
5153
context: ContentFragmentContextType;
54+
contentFragmentId: string;
55+
contentFragmentVersion: ContentFragmentVersion;
5256
};
5357

5458
export type UploadedContentFragment = {

0 commit comments

Comments
 (0)