mirror of
https://github.com/Phundrak/georm.git
synced 2025-11-30 19:03:59 +00:00
feat(examples): add PostgreSQL example with user relationship
Adds an example demonstrating user, comment, and follower relationship including: - User management with profiles - Comments (not really useful, just for showcasing) - Follower/follozing relationships - Ineractive CLI interface with CRUD operations - Database migrations for the example schema
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
DROP TABLE IF EXISTS Followers;
|
||||
DROP TABLE IF EXISTS Comments;
|
||||
DROP TABLE IF EXISTS Profiles;
|
||||
DROP TABLE IF EXISTS Users;
|
||||
@@ -0,0 +1,30 @@
|
||||
-- Add migration script here
|
||||
CREATE TABLE Users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(100) UNIQUE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE Profiles (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INT UNIQUE NOT NULL,
|
||||
bio TEXT,
|
||||
display_name VARCHAR(100),
|
||||
FOREIGN KEY (user_id) REFERENCES Users(id)
|
||||
);
|
||||
|
||||
CREATE TABLE Comments (
|
||||
id SERIAL PRIMARY KEY,
|
||||
author_id INT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
FOREIGN KEY (author_id) REFERENCES Users(id)
|
||||
);
|
||||
|
||||
CREATE TABLE Followers (
|
||||
id SERIAL PRIMARY KEY,
|
||||
followed INT NOT NULL,
|
||||
follower INT NOT NULL,
|
||||
FOREIGN KEY (followed) REFERENCES Users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (follower) REFERENCES Users(id) ON DELETE CASCADE,
|
||||
CHECK (followed != follower),
|
||||
UNIQUE (followed, follower)
|
||||
);
|
||||
Reference in New Issue
Block a user