-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kb): support knowledge base file related api (#23)
Because user should be able to add files into knowledge base. This commit add file related APIs
- Loading branch information
Showing
21 changed files
with
2,724 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
DROP TABLE knowledge_base; | ||
BEGIN; | ||
DROP TABLE knowledge_base; | ||
COMMIT; |
5 changes: 5 additions & 0 deletions
5
pkg/db/migration/000003_re_create_knowledge_base_tables.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
BEGIN; | ||
-- Drop the table knowledge_base_files | ||
DROP TABLE IF EXISTS knowledge_base; | ||
|
||
COMMIT; |
33 changes: 33 additions & 0 deletions
33
pkg/db/migration/000003_re_create_knowledge_base_tables.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
BEGIN; | ||
-- Drop the existing table if exists to avoid conflicts | ||
DROP TABLE IF EXISTS knowledge_base; | ||
-- Create the new knowledge_base table | ||
CREATE TABLE knowledge_base ( | ||
uid UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), | ||
id VARCHAR(255) NOT NULL, | ||
name VARCHAR(255) NOT NULL, | ||
description VARCHAR(1023), | ||
tags VARCHAR(255) [], | ||
owner UUID NOT NULL, | ||
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
delete_time TIMESTAMP | ||
); | ||
-- Add the index | ||
CREATE UNIQUE INDEX idx_unique_owner_name_delete_time ON knowledge_base (owner, name) | ||
WHERE delete_time IS NULL; | ||
CREATE UNIQUE INDEX unique_owner_id_delete_time ON knowledge_base (owner, id) | ||
WHERE delete_time IS NULL; | ||
|
||
-- Comments for the table and columns | ||
COMMENT ON TABLE knowledge_base IS 'Table to store knowledge base information'; | ||
COMMENT ON COLUMN knowledge_base.uid IS 'Primary key, auto-generated UUID'; | ||
COMMENT ON COLUMN knowledge_base.id IS 'Unique identifier from name for the knowledge base, up to 255 characters created from name'; | ||
COMMENT ON COLUMN knowledge_base.name IS 'Name of the knowledge base, up to 255 characters'; | ||
COMMENT ON COLUMN knowledge_base.description IS 'Description of the knowledge base, up to 1023 characters'; | ||
COMMENT ON COLUMN knowledge_base.tags IS 'Array of tags associated with the knowledge base'; | ||
COMMENT ON COLUMN knowledge_base.owner IS 'Owner of the knowledge base. It is a UUID referencing the owner table(uid field).'; | ||
COMMENT ON COLUMN knowledge_base.create_time IS 'Timestamp when the entry was created, stored in UTC'; | ||
COMMENT ON COLUMN knowledge_base.update_time IS 'Timestamp of the last update, stored in UTC'; | ||
COMMENT ON COLUMN knowledge_base.delete_time IS 'Timestamp when the entry was marked as deleted, stored in UTC'; | ||
COMMIT; |
5 changes: 5 additions & 0 deletions
5
pkg/db/migration/000004_create_knowledge_base_file_tables.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
BEGIN; | ||
-- Drop the table knowledge_base_files | ||
DROP TABLE IF EXISTS knowledge_base_files; | ||
|
||
COMMIT; |
37 changes: 37 additions & 0 deletions
37
pkg/db/migration/000004_create_knowledge_base_file_tables.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
BEGIN; | ||
-- Create the table knowledge_base_files | ||
CREATE TABLE knowledge_base_file ( | ||
uid UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
owner UUID NOT NULL, | ||
kb_uid UUID NOT NULL, | ||
creator_uid UUID NOT NULL, | ||
name VARCHAR(255) NOT NULL, | ||
type VARCHAR(100) NOT NULL, | ||
destination VARCHAR(255) NOT NULL, | ||
process_status VARCHAR(100) NOT NULL, | ||
extra_meta_data JSONB, | ||
content BYTEA, | ||
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
delete_time TIMESTAMP | ||
); | ||
|
||
-- Add the unique index on (kb_uid, name) | ||
CREATE UNIQUE INDEX idx_unique_kb_uid_name_delete_time ON knowledge_base_file (kb_uid, name) | ||
WHERE delete_time IS NULL; | ||
|
||
-- Comments for the table and columns | ||
COMMENT ON TABLE knowledge_base_file IS 'Table to store knowledge base files with metadata'; | ||
COMMENT ON COLUMN knowledge_base_file.uid IS 'Unique identifier for the file'; | ||
COMMENT ON COLUMN knowledge_base_file.create_time IS 'Timestamp when the record was created'; | ||
COMMENT ON COLUMN knowledge_base_file.update_time IS 'Timestamp when the record was last updated'; | ||
COMMENT ON COLUMN knowledge_base_file.delete_time IS 'Timestamp when the record was deleted (soft delete)'; | ||
COMMENT ON COLUMN knowledge_base_file.owner IS 'Owner of the file, references owner table''s uid field'; | ||
COMMENT ON COLUMN knowledge_base_file.kb_uid IS 'Knowledge base unique identifier, references knowledge base table''s uid field'; | ||
COMMENT ON COLUMN knowledge_base_file.creator_uid IS 'Creator unique identifier, references owner table''s uid field'; | ||
COMMENT ON COLUMN knowledge_base_file.name IS 'Name of the file'; | ||
COMMENT ON COLUMN knowledge_base_file.process_status IS 'Processing status of the file'; | ||
COMMENT ON COLUMN knowledge_base_file.extra_meta_data IS 'Extra metadata in JSON format, e.g., word count, image count'; | ||
COMMENT ON COLUMN knowledge_base_file.content IS 'File content stored as byte array'; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.