-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(memory-store): Misc fixes; Switch to golang-migrate
Signed-off-by: Diwank Singh Tomer <[email protected]>
- Loading branch information
Showing
30 changed files
with
813 additions
and
370 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### prototyping flow: | ||
|
||
1. Install `pgmigrate` (until I move to golang-migrate) | ||
2. In a separate window, `docker compose up db vectorizer-worker` to start db instances | ||
3. `cd memory-store` and `pgmigrate migrate --database "postgres://postgres:[email protected]:5432/postgres" --migrations ./migrations` to apply the migrations | ||
4. `pip install --user -U pgcli` | ||
5. `pgcli "postgres://postgres:postgres@localhost:5432/postgres"` |
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,17 @@ | ||
-- Drop the update_updated_at_column function | ||
DROP FUNCTION IF EXISTS update_updated_at_column(); | ||
|
||
-- Drop misc extensions | ||
DROP EXTENSION IF EXISTS "uuid-ossp" CASCADE; | ||
DROP EXTENSION IF EXISTS citext CASCADE; | ||
DROP EXTENSION IF EXISTS btree_gist CASCADE; | ||
DROP EXTENSION IF EXISTS btree_gin CASCADE; | ||
|
||
-- Drop timescale's pgai extensions | ||
DROP EXTENSION IF EXISTS ai CASCADE; | ||
DROP EXTENSION IF EXISTS vectorscale CASCADE; | ||
DROP EXTENSION IF EXISTS vector CASCADE; | ||
|
||
-- Drop timescaledb extensions | ||
DROP EXTENSION IF EXISTS timescaledb_toolkit CASCADE; | ||
DROP EXTENSION IF EXISTS timescaledb CASCADE; |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- Drop the table (this will automatically drop associated indexes and triggers) | ||
DROP TABLE IF EXISTS developers CASCADE; | ||
|
||
-- Note: The update_updated_at_column() function is not dropped as it might be used by other tables |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
BEGIN; | ||
|
||
-- Drop trigger first | ||
DROP TRIGGER IF EXISTS update_users_updated_at ON users; | ||
|
||
-- Drop indexes | ||
DROP INDEX IF EXISTS users_metadata_gin_idx; | ||
DROP INDEX IF EXISTS users_developer_id_idx; | ||
DROP INDEX IF EXISTS users_id_sorted_idx; | ||
|
||
-- Drop foreign key constraint | ||
ALTER TABLE IF EXISTS users | ||
DROP CONSTRAINT IF EXISTS users_developer_id_fkey; | ||
|
||
-- Finally drop the table | ||
DROP TABLE IF EXISTS users; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
BEGIN; | ||
|
||
-- Create users table if it doesn't exist | ||
CREATE TABLE IF NOT EXISTS users ( | ||
developer_id UUID NOT NULL, | ||
user_id UUID NOT NULL, | ||
name TEXT NOT NULL, | ||
about TEXT, | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
metadata JSONB NOT NULL DEFAULT '{}'::JSONB, | ||
CONSTRAINT pk_users PRIMARY KEY (developer_id, user_id) | ||
); | ||
|
||
-- Create sorted index on user_id if it doesn't exist | ||
CREATE INDEX IF NOT EXISTS users_id_sorted_idx ON users (user_id DESC); | ||
|
||
-- Create foreign key constraint and index if they don't exist | ||
DO $$ BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 FROM pg_constraint WHERE conname = 'users_developer_id_fkey' | ||
) THEN | ||
ALTER TABLE users | ||
ADD CONSTRAINT users_developer_id_fkey | ||
FOREIGN KEY (developer_id) | ||
REFERENCES developers(developer_id); | ||
END IF; | ||
END $$; | ||
|
||
CREATE INDEX IF NOT EXISTS users_developer_id_idx ON users (developer_id); | ||
|
||
-- Create a GIN index on the entire metadata column if it doesn't exist | ||
CREATE INDEX IF NOT EXISTS users_metadata_gin_idx ON users USING GIN (metadata); | ||
|
||
-- Create trigger if it doesn't exist | ||
DO $$ BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 FROM pg_trigger WHERE tgname = 'update_users_updated_at' | ||
) THEN | ||
CREATE TRIGGER update_users_updated_at | ||
BEFORE UPDATE ON users | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_updated_at_column(); | ||
END IF; | ||
END $$; | ||
|
||
-- Add comment to table (comments are idempotent by default) | ||
COMMENT ON TABLE users IS 'Stores user information linked to developers'; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
BEGIN; | ||
|
||
-- Drop trigger first | ||
DROP TRIGGER IF EXISTS trg_agents_updated_at ON agents; | ||
|
||
-- Drop indexes | ||
DROP INDEX IF EXISTS idx_agents_metadata; | ||
DROP INDEX IF EXISTS idx_agents_developer; | ||
DROP INDEX IF EXISTS idx_agents_id_sorted; | ||
|
||
-- Drop table (this will automatically drop associated constraints) | ||
DROP TABLE IF EXISTS agents; | ||
|
||
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
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,13 @@ | ||
BEGIN; | ||
|
||
-- Drop agent_files table and its dependencies | ||
DROP TABLE IF EXISTS agent_files; | ||
|
||
-- Drop user_files table and its dependencies | ||
DROP TABLE IF EXISTS user_files; | ||
|
||
-- Drop files table and its dependencies | ||
DROP TRIGGER IF EXISTS trg_files_updated_at ON files; | ||
DROP TABLE IF EXISTS files; | ||
|
||
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
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,29 @@ | ||
BEGIN; | ||
|
||
-- Drop indexes | ||
DROP INDEX IF EXISTS idx_docs_content_trgm; | ||
DROP INDEX IF EXISTS idx_docs_title_trgm; | ||
DROP INDEX IF EXISTS idx_docs_search_tsv; | ||
DROP INDEX IF EXISTS idx_docs_metadata; | ||
DROP INDEX IF EXISTS idx_agent_docs_agent; | ||
DROP INDEX IF EXISTS idx_user_docs_user; | ||
DROP INDEX IF EXISTS idx_docs_developer; | ||
DROP INDEX IF EXISTS idx_docs_id_sorted; | ||
|
||
-- Drop triggers | ||
DROP TRIGGER IF EXISTS trg_docs_search_tsv ON docs; | ||
DROP TRIGGER IF EXISTS trg_docs_updated_at ON docs; | ||
|
||
-- Drop the constraint that depends on is_valid_language function | ||
ALTER TABLE IF EXISTS docs DROP CONSTRAINT IF EXISTS ct_docs_valid_language; | ||
|
||
-- Drop functions | ||
DROP FUNCTION IF EXISTS docs_update_search_tsv(); | ||
DROP FUNCTION IF EXISTS is_valid_language(text); | ||
|
||
-- Drop tables (in correct order due to foreign key constraints) | ||
DROP TABLE IF EXISTS agent_docs; | ||
DROP TABLE IF EXISTS user_docs; | ||
DROP TABLE IF EXISTS docs; | ||
|
||
COMMIT; |
Oops, something went wrong.