diff options
author | vulonkaaz <7442677+vulonkaaz@users.noreply.github.com> | 2024-06-19 17:44:29 +0200 |
---|---|---|
committer | vulonkaaz <7442677+vulonkaaz@users.noreply.github.com> | 2024-06-19 17:44:29 +0200 |
commit | 2fe3b4972f02be8b0c6143325d541ddda4b91559 (patch) | |
tree | 5b430810b19e0c6b1112c601b9e64b9e9ec72c61 /database |
Initial version
Diffstat (limited to 'database')
-rw-r--r-- | database/database.go | 17 | ||||
-rw-r--r-- | database/db.sql | 24 |
2 files changed, 41 insertions, 0 deletions
diff --git a/database/database.go b/database/database.go new file mode 100644 index 0000000..90921d5 --- /dev/null +++ b/database/database.go @@ -0,0 +1,17 @@ +package database + +import ( + "log" + "github.com/jmoiron/sqlx" + _ "github.com/lib/pq" +) + +var DB *sqlx.DB + +func DBConnect(connStr string) { + var err error + DB, err = sqlx.Open("postgres", connStr) + if err != nil { + log.Fatal(err) + } +} diff --git a/database/db.sql b/database/db.sql new file mode 100644 index 0000000..0327b12 --- /dev/null +++ b/database/db.sql @@ -0,0 +1,24 @@ +-- Database structure of penchan.club +-- Every post is stored in the post table +-- there can be multiple boards, they don't need to have their own table, by default posts go to /b/ +-- picture is a base64 png data URL +-- thread point to the OP of a thread, if thread is null the post begin a new thread +-- reply_to is if someone wanna reply to someone else +-- ip_address is poster's IP, in case someone spam CP and my server get seized +-- special is mostly to mark messages as being sent by VIPs (like mods or site admin) + +BEGIN; + +CREATE TABLE "post" ( + "id" int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + "board" text DEFAULT 'b', + "picture" text NOT NULL, + "thread" int REFERENCES "post"("id"), + "reply_to" int REFERENCES "post"("id"), + "ip_address" text, + "special" text, + "created_at" timestamptz NOT NULL DEFAULT now(), + "updated_at" timestamptz +); + +COMMIT; |