# migrations

dir: embeddings_queue
filename: 00001-embeddings.sqlite.sql
hash: d3755dfd232be8e8301f4d7fcfb3a486
sql:
CREATE TABLE embeddings_queue (
    seq_id INTEGER PRIMARY KEY,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    operation INTEGER NOT NULL,
    topic TEXT NOT NULL,
    id TEXT NOT NULL,
    vector BLOB,
    encoding TEXT,
    metadata TEXT
);


dir: sysdb
filename: 00001-collections.sqlite.sql
hash: 38352d725ad1c16074fac420b22b4633
sql:
CREATE TABLE collections (
    id TEXT PRIMARY KEY,
    name TEXT NOT NULL,
    topic TEXT NOT NULL,
    UNIQUE (name)
);

CREATE TABLE collection_metadata (
    collection_id TEXT REFERENCES collections(id) ON DELETE CASCADE,
    key TEXT NOT NULL,
    str_value TEXT,
    int_value INTEGER,
    float_value REAL,
    PRIMARY KEY (collection_id, key)
);


dir: sysdb
filename: 00002-segments.sqlite.sql
hash: 2913cb6a503055a95f625448037e8912
sql:
CREATE TABLE segments (
    id TEXT PRIMARY KEY,
    type TEXT NOT NULL,
    scope TEXT NOT NULL,
    topic TEXT,
    collection TEXT REFERENCES collection(id)
);

CREATE TABLE segment_metadata (
    segment_id TEXT  REFERENCES segments(id) ON DELETE CASCADE,
    key TEXT NOT NULL,
    str_value TEXT,
    int_value INTEGER,
    float_value REAL,
    PRIMARY KEY (segment_id, key)
);


dir: sysdb
filename: 00004-tenants-databases.sqlite.sql
hash: 048867ce8fcdefe4023c7110e4433591
sql:
CREATE TABLE IF NOT EXISTS tenants (
    id TEXT PRIMARY KEY,
    UNIQUE (id)
);

CREATE TABLE IF NOT EXISTS databases (
    id TEXT PRIMARY KEY, -- unique globally
    name TEXT NOT NULL, -- unique per tenant
    tenant_id TEXT NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
    UNIQUE (tenant_id, name) -- Ensure that a tenant has only one database with a given name
);

CREATE TABLE IF NOT EXISTS collections_tmp (
    id TEXT PRIMARY KEY, -- unique globally
    name TEXT NOT NULL, -- unique per database
    topic TEXT NOT NULL,
    dimension INTEGER,
    database_id TEXT NOT NULL REFERENCES databases(id) ON DELETE CASCADE,
    UNIQUE (name, database_id)
);

-- Create default tenant and database
INSERT OR REPLACE INTO tenants (id) VALUES ('default_tenant'); -- The default tenant id is 'default_tenant' others are UUIDs
INSERT OR REPLACE INTO databases (id, name, tenant_id) VALUES ('00000000-0000-0000-0000-000000000000', 'default_database', 'default_tenant');

INSERT OR REPLACE INTO collections_tmp (id, name, topic, dimension, database_id)
    SELECT id, name, topic, dimension, '00000000-0000-0000-0000-000000000000' FROM collections;
DROP TABLE collections;
ALTER TABLE collections_tmp RENAME TO collections;


dir: sysdb
filename: 00005-remove-topic.sqlite.sql
hash: b1367c826b8fba5f96f27befdc1d42d2
sql:
-- Remove the topic column from the Collections and Segments tables

ALTER TABLE collections DROP COLUMN topic;
ALTER TABLE segments DROP COLUMN topic;


dir: sysdb
filename: 00006-collection-segment-metadata.sqlite.sql
hash: 4eea7468935bf25d4604a0fed2366116
sql:
-- SQLite does not support adding check with alter table, as a result, adding a check
-- involve creating a new table and copying the data over. It is over kill with adding
-- a boolean type column. The application write to the table needs to ensure the data
-- integrity.
ALTER TABLE collection_metadata ADD COLUMN bool_value INTEGER;
ALTER TABLE segment_metadata ADD COLUMN bool_value INTEGER;


dir: metadb
filename: 00001-embedding-metadata.sqlite.sql
hash: 2b4cf52c4bb2676e21d6860a4409f856
sql:
CREATE TABLE embeddings (
    id INTEGER PRIMARY KEY,
    segment_id TEXT NOT NULL,
    embedding_id TEXT NOT NULL,
    seq_id BLOB NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE (segment_id, embedding_id)
);

CREATE TABLE embedding_metadata (
    id INTEGER REFERENCES embeddings(id),
    key TEXT NOT NULL,
    string_value TEXT,
    int_value INTEGER,
    float_value REAL,
    PRIMARY KEY (id, key)
);

CREATE TABLE max_seq_id (
    segment_id TEXT PRIMARY KEY,
    seq_id BLOB NOT NULL
);

CREATE VIRTUAL TABLE embedding_fulltext USING fts5(id, string_value);


dir: metadb
filename: 00002-embedding-metadata.sqlite.sql
hash: 12a570f7121b3a8ce750a2a7c36da20f
sql:
-- SQLite does not support adding check with alter table, as a result, adding a check
-- involve creating a new table and copying the data over. It is over kill with adding
-- a boolean type column. The application write to the table needs to ensure the data
-- integrity.
ALTER TABLE embedding_metadata ADD COLUMN bool_value INTEGER


dir: metadb
filename: 00003-full-text-tokenize.sqlite.sql
hash: f97ad6334aeaa8f419f01110b648b97a
sql:
CREATE VIRTUAL TABLE embedding_fulltext_search USING fts5(string_value, tokenize='trigram');
INSERT INTO embedding_fulltext_search (rowid, string_value) SELECT rowid, string_value FROM embedding_metadata;
DROP TABLE embedding_fulltext;


# embeddings_queue

created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: a8d455ac-b803-423d-a7ec-b3f7cf98a381
encoding: FLOAT32
metadata:
{"chroma:document": "\u53f0\u7063\u70ba\u4ec0\u9ebc\u8981\u5236\u5b9a\u6c23\u5019\u8b8a\u9077\u56e0\u61c9\u6cd5\uff1f"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: e42f27b2-56b9-43ec-8d6e-f8112278ed11
encoding: FLOAT32
metadata:
{"chroma:document": "\u4f55\u985e\u5c0d\u8c61\u9700\u57f7\u884c\u6eab\u5ba4\u6c23\u9ad4\u76e4\u67e5"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: e6dc2b83-aa7c-4282-aa8a-c253d6abe638
encoding: FLOAT32
metadata:
{"chroma:document": "\u4f55\u8b02\u7e3d\u91cf\u7ba1\u5236\uff0c\u6211\u570b\u662f\u5426\u5df2\u8a2d\u5b9a\u7e3d\u91cf\u7ba1\u5236"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: 61c8e63e-8403-4b3d-b56e-a09722b2123d
encoding: FLOAT32
metadata:
{"chroma:document": "\u7d44\u7e54\u6eab\u5ba4\u6c23\u9ad4\u6392\u653e\u91cf\u53ef\u4ee5\u7528\u78b3\u6b0a\u62b5\u6e1b\u55ce\uff1f"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: 896f96db-9362-4131-b199-dd39a2d9fcf7
encoding: FLOAT32
metadata:
{"chroma:document": "\u8001\u820a\u6c7d\u8eca\u6c70\u820a\u63db\u65b0\u6eab\u5ba4\u6c23\u9ad4\u6e1b\u91cf\u6548\u76ca\u7684\u7528\u9014\u70ba\u4f55"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: 83a4ab15-0708-4690-bfcd-3172e95874c4
encoding: FLOAT32
metadata:
{"chroma:document": "\u5b8c\u6210\u76e4\u67e5\u4f5c\u696d\u5f8c\uff0c\u9700\u7522\u51fa\u4f55\u7a2e\u6587\u4ef6"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: c38b14ab-7da9-4f04-882a-6440cb19df1f
encoding: FLOAT32
metadata:
{"chroma:document": "\u7d44\u7e54\u578b\u76e4\u67e5\u662f\u5426\u7686\u9700\u5b8c\u6210\u7b2c\u4e09\u8005\u67e5\u8b49\u4f5c\u696d"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: 58d7affb-0270-4ba9-8b16-e01d02e3bb36
encoding: FLOAT32
metadata:
{"chroma:document": "CEV\u7cfb\u7d71\u53ef\u4ee5\u652f\u63f4\u76e4\u67e5\u5230\u4ec0\u9ebc\u7a0b\u5ea6"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: af1b9770-8bba-4d33-b48f-d7e92870744d
encoding: FLOAT32
metadata:
{"chroma:document": "\u78b3\u76e4\u67e5\u6d89\u53ca\u54ea\u4e9b\u7522\u696d\u6216\u9818\u57df\uff1f"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: 4bb23532-75d7-43df-996b-18e2005b6722
encoding: FLOAT32
metadata:
{"chroma:document": "\u53f0\u7063\u6c23\u5019\u8b8a\u9077\u6cd5\u662f\u5426\u5df2\u8a2d\u7acb\u5404\u968e\u6bb5\u7ba1\u5236\u76ee\u6a19?"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: 304fd735-3e46-407e-9232-95925326dac7
encoding: FLOAT32
metadata:
{"chroma:document": "\u5236\u5b9a\u6eab\u5ba4\u6c23\u9ad4\u6392\u653e\u91cf\u76e4\u67e5\u767b\u9304\u53ca\u67e5\u9a57\u7ba1\u7406\u8fa6\u6cd5\u7684\u76ee\u7684\u662f\u4ec0\u9ebc"}


created_at: 2024-07-18 01:15:04
topic: persistent://default/default/29223c4a-7ef3-41aa-8efa-282729282704
id: 86721d8a-1a29-4634-8b3c-d8f9cbc93bc0
encoding: FLOAT32
metadata:
{"chroma:document": "\u8acb\u554f\u7cbe\u8aa0\u8cc7\u8a0a\u6709\u4ec0\u9ebc\u7522\u54c1\u5462\uff1f"}


