docs(migration): updated table

This commit is contained in:
Stan Girard 2023-07-03 14:41:33 +02:00
parent dcaa70a947
commit f0a30b8452
7 changed files with 10 additions and 11 deletions

View File

@ -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;")

View File

@ -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'
);

View File

@ -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'
);

View File

@ -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'
);

View File

@ -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'
);

View File

@ -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'
);

View File

@ -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'
);