From 12968a75af13d417673825acd5aaf20f6a299485 Mon Sep 17 00:00:00 2001 From: Toby Scott Date: Sat, 4 Nov 2023 12:24:32 +1100 Subject: [PATCH] Add syntax highlighting to Postgres example --- database/postgres/TUTORIAL.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/database/postgres/TUTORIAL.md b/database/postgres/TUTORIAL.md index 0f19c56ff..6ab98906a 100644 --- a/database/postgres/TUTORIAL.md +++ b/database/postgres/TUTORIAL.md @@ -27,7 +27,7 @@ If there were no errors, we should have two files available under `db/migrations Note the `sql` extension that we provided. In the `.up.sql` file let's create the table: -``` +```sql CREATE TABLE IF NOT EXISTS users( user_id serial PRIMARY KEY, username VARCHAR (50) UNIQUE NOT NULL, @@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS users( ); ``` And in the `.down.sql` let's delete it: -``` +```sql DROP TABLE IF EXISTS users; ``` By adding `IF EXISTS/IF NOT EXISTS` we are making migrations idempotent - you can read more about idempotency in [getting started](../../GETTING_STARTED.md#create-migrations) @@ -79,7 +79,7 @@ Again, it should create for us two migrations files: In Postgres, when we want our queries to be done in a transaction, we need to wrap it with `BEGIN` and `COMMIT` commands. In our example, we are going to add a column to our database that can only accept enumerable values or NULL. Migration up: -``` +```sql BEGIN; CREATE TYPE enum_mood AS ENUM ( @@ -92,7 +92,7 @@ ALTER TABLE users ADD COLUMN mood enum_mood; COMMIT; ``` Migration down: -``` +```sql BEGIN; ALTER TABLE users DROP COLUMN mood; @@ -124,7 +124,7 @@ Indexes: ## Optional: Run migrations within your Go app Here is a very simple app running migrations for the above configuration: -``` +```go import ( "log"