~jan0sch/smederee

Showing details for patch 85b2382c3b8604a7e3c41f6d491292318a372789.
2023-01-16 (Mon), 7:07 PM - Jens Grassel - 85b2382c3b8604a7e3c41f6d491292318a372789

Update coding style.

Summary of changes
1 files modified with 39 lines added and 1 lines removed
  • CODINGSTYLE.md with 39 added and 1 removed lines
diff -rN -u old-smederee/CODINGSTYLE.md new-smederee/CODINGSTYLE.md
--- old-smederee/CODINGSTYLE.md	2025-02-01 01:54:54.870869928 +0000
+++ new-smederee/CODINGSTYLE.md	2025-02-01 01:54:54.870869928 +0000
@@ -28,7 +28,7 @@
 
 **TODO**: Describe `danglingParentheses.preset = true`
 
-## 3 Build configuration file style (sbt)
+## 3. Build configuration file style (sbt)
 
 1. Build definition and settings SHOULD be formatted to have one setting per line if possible.
 2. Dependencies SHALL be defined in the `lazy val library` block inside the `build.sbt` file, following these rules:
@@ -45,3 +45,41 @@
    addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
    ```
 
+## 4. SQL
+
+The application contains database migrations files and SQL commands / queries for these the following rules apply:
+
+1. All SQL keywords MUST be written in uppercase.
+2. All table, column and variable names MUST be written in lowercase.
+3. All table and column names MUST be enclosed in double quotes e.g. `"table"."column"`.
+4. Created tables MUST be described using the `COMMENT` command. This also applies to each column of a table.
+5. A `COMMENT` statement SHALL NOT be wrapped even if it exceeds 80 characters.
+6. A `CREATE TABLE` statement MUST be split over multiple lines to have the `CREATE TABLE`, the starting parenthesis, each column and constraint and the closing parenthesis on a separate line.
+7. A `CONSTRAINT` line MAY be wrapped to span multiple lines if it exceeds 80 characters.
+8. The parameters for the column definitions SHOULD be vertically aligned.
+9. A created table MUST NOT use OIDs i.e. the `CREATE TABLE` statement MUST end with `WITH (OIDS=FALSE);`.
+
+An example for a database migration SQL file looks like this:
+
+```sql
+CREATE TABLE "sessions"
+(
+  "id"         VARCHAR(32)              NOT NULL,
+  "uid"        UUID                     NOT NULL,
+  "created_at" TIMESTAMP WITH TIME ZONE NOT NULL,
+  "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL,
+  CONSTRAINT "sessions_pk"     PRIMARY KEY ("id"),
+  CONSTRAINT "sessions_fk_uid" FOREIGN KEY ("uid")
+    REFERENCES "accounts" ("uid") ON UPDATE CASCADE ON DELETE CASCADE
+)
+WITH (
+  OIDS=FALSE
+);
+
+COMMENT ON TABLE "sessions" IS 'Keeps the sessions of users.';
+COMMENT ON COLUMN "sessions"."id" IS 'A globally unique session ID.';
+COMMENT ON COLUMN "sessions"."uid" IS 'The unique ID of the user account to whom the session belongs.';
+COMMENT ON COLUMN "sessions"."created_at" IS 'The timestamp of when the session was created.';
+COMMENT ON COLUMN "sessions"."updated_at" IS 'The session ID should be re-generated in regular intervals resulting in a copy of the old session entry with a new ID and the corresponding timestamp in this column.';
+```
+