-
Notifications
You must be signed in to change notification settings - Fork 1
Writing and inserting SQL Scripts
When you are writing a new SQL script for the project - please follow these guidelines:
If the script you are writing replaces an existing function's parameters or output - include the DROP FUNCTION
line.
what happens if you don't do it is the previous function stays (because PostgreSQL recognizes 2 different functions with 2 parameters).
However if the script you are writing creates a new function - do not include the DROP FUNCTION
line
When you are writing any script (especially if it changes tables structure), please try to utilize PostgreSQL IF NOT EXISTS
function or add exceptions so the script's run would not count as a fail.
take this example:
lets say that the table USERS
already have an 'age' column
ALTER TABLE USERS ADD COLUMN age integer
-> ❌ ERROR : column 'age' already exists
ALTER TABLE USERS ADD COLUMN IF NOT EXISTS age integer
-> ✔️ column 'age' already exists, skipping...
ALTER TABLE public.USERS OWNER to coronai
doesn't really do anything - my guess is that it's created automatically from the user it tried to change.
we only have one user in the DB (whether that's coronai or postgres) so please don't leave that part in.
in order to insert SQL scripts automatically to the system use Script Runner (🏃 💨) - add the script to the SCRIPTS_DIRECTORY (read Scripts Runnder readme for more info)