Skip to content

Commit

Permalink
docs(migration): updated table
Browse files Browse the repository at this point in the history
  • Loading branch information
StanGirard committed Jul 3, 2023
1 parent dcaa70a commit f0a30b8
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ else
fi

# Ask user whether to create tables or run migrations
CHOICE=$(gum choose --header "Choose an option" "create_tables" "run_migrations")
CHOICE=$(gum choose --header "Choose an option" "Create all tables" "Run Migrations")

if [ "$CHOICE" == "create_tables" ]; then
if [ "$CHOICE" == "Create all tables" ]; then
# Running the tables.sql file to create tables
run_sql_file "scripts/tables.sql"
else
# Running migrations

# Get the last migration that was executed
LAST_MIGRATION=$(PGPASSWORD=${DB_PASSWORD} psql -h "${DB_HOST}" -p "${DB_PORT}" -d "${DB_NAME}" -U "${DB_USER}" -tAc "SELECT name FROM migrations ORDER BY executed_at DESC LIMIT 1;")
Expand Down
2 changes: 1 addition & 1 deletion scripts/20230606131110_add_uuid_user_id.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ END;
$$ LANGUAGE plpgsql;

INSERT INTO migrations (name)
SELECT ('20230606131110_add_uuid_user_id')
SELECT '20230606131110_add_uuid_user_id'
WHERE NOT EXISTS (
SELECT 1 FROM migrations WHERE name = '20230606131110_add_uuid_user_id'
);
Expand Down
2 changes: 1 addition & 1 deletion scripts/20230620170840_add_vectors_brains.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ $$;


INSERT INTO migrations (name)
SELECT ('20230620170840_add_vectors_brains')
SELECT '20230620170840_add_vectors_brains'
WHERE NOT EXISTS (
SELECT 1 FROM migrations WHERE name = '20230620170840_add_vectors_brains'
);
2 changes: 1 addition & 1 deletion scripts/20230620183620_use_supabase_user_id.sql
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ $$;
--ALTER TABLE users DROP COLUMN old_user_id;

INSERT INTO migrations (name)
SELECT ('20230627151100_update_match_vectors')
SELECT '20230627151100_update_match_vectors'
WHERE NOT EXISTS (
SELECT 1 FROM migrations WHERE name = '20230627151100_update_match_vectors'
);
2 changes: 1 addition & 1 deletion scripts/20230627151100_update_match_vectors.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ END;
$$;

INSERT INTO migrations (name)
SELECT ('20230627151100_update_match_vectors');
SELECT '20230627151100_update_match_vectors';
WHERE NOT EXISTS (
SELECT 1 FROM migrations WHERE name = '20230627151100_update_match_vectors'
);
Expand Down
3 changes: 2 additions & 1 deletion scripts/20230629143400_add_file_sha1_brains_vectors.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ FROM (
WHERE brains_vectors.vector_id = subquery.id
AND (brains_vectors.file_sha1 IS NULL OR brains_vectors.file_sha1 = '');


INSERT INTO migrations (name)
SELECT ('20230629143400_add_file_sha1_brains_vectors')
SELECT '20230629143400_add_file_sha1_brains_vectors'
WHERE NOT EXISTS (
SELECT 1 FROM migrations WHERE name = '20230629143400_add_file_sha1_brains_vectors'
);
Expand Down
5 changes: 2 additions & 3 deletions scripts/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,12 @@ CREATE TABLE IF NOT EXISTS brains_vectors (
);

CREATE TABLE IF NOT EXISTS migrations (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
name VARCHAR(255) PRIMARY KEY,
executed_at TIMESTAMPTZ DEFAULT current_timestamp
);

INSERT INTO migrations (name)
SELECT ('20230629143400_add_file_sha1_brains_vectors')
SELECT '20230629143400_add_file_sha1_brains_vectors'
WHERE NOT EXISTS (
SELECT 1 FROM migrations WHERE name = '20230629143400_add_file_sha1_brains_vectors'
);

0 comments on commit f0a30b8

Please sign in to comment.