From 8781ba0d58f50c0a27067294a8dd157303f1f960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daphn=C3=A9=20Popin?= Date: Wed, 4 Dec 2024 15:30:15 +0100 Subject: [PATCH] Revert "Doc tracker models (#9114)" (#9125) This reverts commit 1741d81d90b59f60eceea64553901f1d51bfa5b3. --- front/admin/db.ts | 7 - front/lib/models/doc_tracker.ts | 273 -------------------------- front/migrations/db/migration_124.sql | 52 ----- 3 files changed, 332 deletions(-) delete mode 100644 front/migrations/db/migration_124.sql diff --git a/front/admin/db.ts b/front/admin/db.ts index d4fe9b1d62c8..256e7b23f8ba 100644 --- a/front/admin/db.ts +++ b/front/admin/db.ts @@ -49,9 +49,6 @@ import { ConversationClassification } from "@app/lib/models/conversation_classif import { DocumentTrackerChangeSuggestion, TrackedDocument, - TrackerConfigurationModel, - TrackerDataSouceConfigurationModel, - TrackerGenerationModel, } from "@app/lib/models/doc_tracker"; import { FeatureFlag } from "@app/lib/models/feature_flag"; import { Plan, Subscription } from "@app/lib/models/plan"; @@ -125,10 +122,6 @@ async function main() { await TrackedDocument.sync({ alter: true }); await DocumentTrackerChangeSuggestion.sync({ alter: true }); - await TrackerConfigurationModel.sync({ alter: true }); - await TrackerDataSouceConfigurationModel.sync({ alter: true }); - await TrackerGenerationModel.sync({ alter: true }); - await Plan.sync({ alter: true }); await Subscription.sync({ alter: true }); await TemplateModel.sync({ alter: true }); diff --git a/front/lib/models/doc_tracker.ts b/front/lib/models/doc_tracker.ts index 75ad3e4b20e0..215311390a04 100644 --- a/front/lib/models/doc_tracker.ts +++ b/front/lib/models/doc_tracker.ts @@ -3,285 +3,12 @@ import type { ForeignKey, InferAttributes, InferCreationAttributes, - NonAttribute, } from "sequelize"; import { DataTypes, Model } from "sequelize"; import { User } from "@app/lib/models/user"; -import { Workspace } from "@app/lib/models/workspace"; import { frontSequelize } from "@app/lib/resources/storage"; import { DataSourceModel } from "@app/lib/resources/storage/models/data_source"; -import { DataSourceViewModel } from "@app/lib/resources/storage/models/data_source_view"; -import { SpaceModel } from "@app/lib/resources/storage/models/spaces"; -import { SoftDeletableModel } from "@app/lib/resources/storage/wrappers"; - -export class TrackerConfigurationModel extends SoftDeletableModel { - declare id: CreationOptional; - declare createdAt: CreationOptional; - declare updatedAt: CreationOptional; - - declare status: "active" | "inactive"; - - declare modelId: string; - declare providerId: string; - declare temperature: number; - - declare prompt: string | null; - - declare frequency: string | null; - - declare recipients: string[] | null; - - declare workspaceId: ForeignKey; - declare spaceId: ForeignKey; - declare userId: ForeignKey | null; // If a user is deleted, the tracker should still be available - - declare workspace: NonAttribute; - declare space: NonAttribute; - declare user: NonAttribute | null; -} - -TrackerConfigurationModel.init( - { - id: { - type: DataTypes.INTEGER, - autoIncrement: true, - primaryKey: true, - }, - createdAt: { - type: DataTypes.DATE, - allowNull: false, - defaultValue: DataTypes.NOW, - }, - updatedAt: { - type: DataTypes.DATE, - allowNull: false, - defaultValue: DataTypes.NOW, - }, - deletedAt: { - type: DataTypes.DATE, - }, - status: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: "active", - }, - modelId: { - type: DataTypes.STRING, - allowNull: false, - }, - providerId: { - type: DataTypes.STRING, - allowNull: false, - }, - temperature: { - type: DataTypes.FLOAT, - allowNull: false, - defaultValue: 0.7, - }, - prompt: { - type: DataTypes.TEXT, - allowNull: true, - }, - frequency: { - type: DataTypes.STRING, - allowNull: true, - }, - recipients: { - type: DataTypes.ARRAY(DataTypes.STRING), - allowNull: true, - }, - }, - { - modelName: "tracker_configuration", - sequelize: frontSequelize, - indexes: [{ fields: ["workspaceId"] }], - } -); - -Workspace.hasMany(TrackerConfigurationModel, { - foreignKey: { allowNull: false }, - onDelete: "RESTRICT", -}); - -TrackerConfigurationModel.belongsTo(Workspace, { - foreignKey: { allowNull: false }, -}); - -SpaceModel.hasMany(TrackerConfigurationModel, { - foreignKey: { allowNull: false }, - onDelete: "RESTRICT", -}); - -TrackerConfigurationModel.belongsTo(SpaceModel, { - foreignKey: { allowNull: false }, -}); - -User.hasMany(TrackerConfigurationModel, { - foreignKey: { allowNull: true }, - onDelete: "RESTRICT", -}); - -TrackerConfigurationModel.belongsTo(User, { - foreignKey: { allowNull: true }, -}); - -export class TrackerDataSouceConfigurationModel extends SoftDeletableModel { - declare id: CreationOptional; - declare createdAt: CreationOptional; - declare updatedAt: CreationOptional; - - declare scope: "maintained" | "watched"; - declare parentsIn: string[] | null; - declare parentsNotIn: string[] | null; - - declare trackerConfigurationId: ForeignKey; - - declare dataSourceId: ForeignKey; - declare dataSourceViewId: ForeignKey; - - declare trackerConfiguration: NonAttribute; - declare dataSource: NonAttribute; - declare dataSourceView: NonAttribute; -} - -TrackerDataSouceConfigurationModel.init( - { - id: { - type: DataTypes.INTEGER, - autoIncrement: true, - primaryKey: true, - }, - createdAt: { - type: DataTypes.DATE, - allowNull: false, - defaultValue: DataTypes.NOW, - }, - updatedAt: { - type: DataTypes.DATE, - allowNull: false, - defaultValue: DataTypes.NOW, - }, - deletedAt: { - type: DataTypes.DATE, - }, - scope: { - type: DataTypes.STRING, - allowNull: false, - }, - parentsIn: { - type: DataTypes.ARRAY(DataTypes.STRING), - allowNull: true, - }, - parentsNotIn: { - type: DataTypes.ARRAY(DataTypes.STRING), - allowNull: true, - }, - }, - { - modelName: "tracker_data_source_configuration", - sequelize: frontSequelize, - indexes: [{ fields: ["trackerConfigurationId"] }], - } -); - -TrackerConfigurationModel.hasMany(TrackerDataSouceConfigurationModel, { - foreignKey: { allowNull: false }, - onDelete: "RESTRICT", -}); -TrackerDataSouceConfigurationModel.belongsTo(TrackerConfigurationModel, { - foreignKey: { allowNull: false }, -}); - -DataSourceModel.hasMany(TrackerDataSouceConfigurationModel, { - foreignKey: { allowNull: false }, - onDelete: "RESTRICT", -}); -TrackerDataSouceConfigurationModel.belongsTo(DataSourceModel, { - foreignKey: { allowNull: false }, -}); - -DataSourceViewModel.hasMany(TrackerDataSouceConfigurationModel, { - foreignKey: { allowNull: false }, - onDelete: "RESTRICT", -}); -TrackerDataSouceConfigurationModel.belongsTo(DataSourceViewModel, { - foreignKey: { allowNull: false }, -}); - -export class TrackerGenerationModel extends SoftDeletableModel { - declare id: CreationOptional; - declare createdAt: CreationOptional; - declare updatedAt: CreationOptional; - - declare content: string; - declare thinking: string | null; - - declare trackerConfigurationId: ForeignKey; - declare dataSourceId: ForeignKey; - declare documentId: string; - - declare trackerConfiguration: NonAttribute; -} - -TrackerGenerationModel.init( - { - id: { - type: DataTypes.INTEGER, - autoIncrement: true, - primaryKey: true, - }, - createdAt: { - type: DataTypes.DATE, - allowNull: false, - defaultValue: DataTypes.NOW, - }, - updatedAt: { - type: DataTypes.DATE, - allowNull: false, - defaultValue: DataTypes.NOW, - }, - deletedAt: { - type: DataTypes.DATE, - }, - content: { - type: DataTypes.TEXT, - allowNull: false, - }, - thinking: { - type: DataTypes.TEXT, - allowNull: true, - }, - documentId: { - type: DataTypes.STRING, - allowNull: false, - }, - }, - { - modelName: "tracker_generation", - sequelize: frontSequelize, - indexes: [{ fields: ["trackerConfigurationId"] }], - } -); - -TrackerConfigurationModel.hasMany(TrackerGenerationModel, { - foreignKey: { allowNull: false }, - onDelete: "RESTRICT", -}); -TrackerGenerationModel.belongsTo(TrackerConfigurationModel, { - foreignKey: { allowNull: false }, -}); - -DataSourceModel.hasMany(TrackerGenerationModel, { - foreignKey: { allowNull: false }, - onDelete: "RESTRICT", -}); -TrackerGenerationModel.belongsTo(DataSourceModel, { - foreignKey: { allowNull: false }, -}); - -// TODO(DOC_TRACKER) Delete models below this line -// They will be replaced by the new models export class TrackedDocument extends Model< InferAttributes, diff --git a/front/migrations/db/migration_124.sql b/front/migrations/db/migration_124.sql deleted file mode 100644 index cbb32110ce33..000000000000 --- a/front/migrations/db/migration_124.sql +++ /dev/null @@ -1,52 +0,0 @@ --- Migration created on Dec 04, 2024 - -CREATE TABLE IF NOT EXISTS "tracker_configurations" ( - "id" SERIAL, - "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, - "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, - "deletedAt" TIMESTAMP WITH TIME ZONE, - "status" VARCHAR(255) NOT NULL DEFAULT 'active', - "modelId" VARCHAR(255) NOT NULL, - "providerId" VARCHAR(255) NOT NULL, - "temperature" FLOAT NOT NULL DEFAULT '0.7', - "prompt" TEXT, - "frequency" VARCHAR(255), - "recipients" VARCHAR(255)[], - "workspaceId" INTEGER NOT NULL REFERENCES "workspaces" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - "spaceId" INTEGER NOT NULL REFERENCES "vaults" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - "userId" INTEGER REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - PRIMARY KEY ("id") -); - -CREATE INDEX "tracker_configurations_workspace_id" ON "tracker_configurations" ("workspaceId"); - -CREATE TABLE IF NOT EXISTS "tracker_data_source_configurations" ( - "id" SERIAL, - "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, - "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, - "deletedAt" TIMESTAMP WITH TIME ZONE, - "scope" VARCHAR(255) NOT NULL, - "parentsIn" VARCHAR(255)[], - "parentsNotIn" VARCHAR(255)[], - "trackerConfigurationId" INTEGER NOT NULL REFERENCES "tracker_configurations" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - "dataSourceId" INTEGER NOT NULL REFERENCES "data_sources" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - "dataSourceViewId" INTEGER NOT NULL REFERENCES "data_source_views" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - PRIMARY KEY ("id") -); - -CREATE INDEX "tracker_data_source_configurations_tracker_configuration_id" ON "tracker_data_source_configurations" ("trackerConfigurationId"); - -CREATE TABLE IF NOT EXISTS "tracker_generations" ( - "id" SERIAL, - "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, - "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, - "deletedAt" TIMESTAMP WITH TIME ZONE, - "content" TEXT NOT NULL, - "thinking" TEXT, - "documentId" VARCHAR(255) NOT NULL, - "trackerConfigurationId" INTEGER NOT NULL REFERENCES "tracker_configurations" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - "dataSourceId" INTEGER NOT NULL REFERENCES "data_sources" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - PRIMARY KEY ("id") -); - -CREATE INDEX "tracker_generations_tracker_configuration_id" ON "tracker_generations" ("trackerConfigurationId");