Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: add version (superseded | latest) to content frags #8678

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions front/lib/api/assistant/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,7 @@ export async function postNewContentFragment(
userContextEmail: context?.email,
userContextFullName: context?.fullName,
userContextUsername: context?.username,
version: "latest",
},
t
);
Expand Down
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
Loading