-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from indnb/refactor/architecture
Refactor/architecture
- Loading branch information
Showing
92 changed files
with
793 additions
and
780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,23 @@ | ||
-- This file was automatically created by Diesel to setup helper functions | ||
-- and other internal bookkeeping. This file is safe to edit, any future | ||
-- changes will be added to existing projects as new migrations. | ||
|
||
|
||
|
||
|
||
-- Sets up a trigger for the given table to automatically set a column called | ||
-- `updated_at` whenever the row is modified (unless `updated_at` was included | ||
-- in the modified columns) | ||
-- | ||
-- # Example | ||
-- | ||
-- ```sql | ||
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW()); | ||
-- | ||
-- SELECT diesel_manage_updated_at('users'); | ||
-- ``` | ||
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ | ||
CREATE | ||
OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ | ||
BEGIN | ||
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s | ||
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s | ||
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl); | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
$$ | ||
LANGUAGE plpgsql; | ||
|
||
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$ | ||
CREATE | ||
OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$ | ||
BEGIN | ||
IF ( | ||
IF | ||
( | ||
NEW IS DISTINCT FROM OLD AND | ||
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at | ||
) THEN | ||
NEW.updated_at := current_timestamp; | ||
END IF; | ||
RETURN NEW; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
$$ | ||
LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,144 @@ | ||
-- Enum Definitions | ||
CREATE TYPE user_role AS ENUM ('Admin', 'User'); | ||
CREATE TYPE hackathon_category AS ENUM ('education', 'military', 'web3_0', 'cybersecurity'); | ||
CREATE TYPE hackathon_category_2024 AS ENUM ('education', 'military', 'web3_0', 'cybersecurity'); | ||
CREATE TYPE type_media AS ENUM ('video', 'photo'); | ||
|
||
-- Function for Updated Timestamp | ||
CREATE OR REPLACE FUNCTION update_timestamp() | ||
CREATE | ||
OR REPLACE FUNCTION update_timestamp() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
NEW.updated_at = CURRENT_TIMESTAMP; | ||
NEW.updated_at | ||
= CURRENT_TIMESTAMP; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
$$ | ||
LANGUAGE plpgsql; | ||
|
||
-- Users Table | ||
CREATE TABLE users ( | ||
id SERIAL PRIMARY KEY, | ||
first_name VARCHAR(50) NOT NULL, | ||
last_name VARCHAR(50) NOT NULL, | ||
password_hash VARCHAR(255) NOT NULL, | ||
phone VARCHAR(20) NOT NULL UNIQUE, | ||
email VARCHAR(255) NOT NULL UNIQUE, | ||
role user_role NOT NUll, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
-- University Table | ||
CREATE TABLE hackathon_university_2024 | ||
( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL UNIQUE, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TRIGGER update_users_updated_at | ||
BEFORE UPDATE ON users | ||
CREATE TRIGGER update_hackathon_university_updated_at | ||
BEFORE UPDATE | ||
ON hackathon_university_2024 | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_timestamp(); | ||
|
||
-- Hackathon Table | ||
CREATE TABLE hackathon ( | ||
id SERIAL PRIMARY KEY, | ||
user_id INT NOT NULL REFERENCES users(id) ON DELETE CASCADE, | ||
category hackathon_category NOT NULL, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
-- Hackathon Team Table | ||
CREATE TABLE hackathon_team_2024 | ||
( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
category hackathon_category_2024 NOT NULL, | ||
password_registration VARCHAR(255) NOT NULL, | ||
count_members INT NOT NULL DEFAULT 0, | ||
nickname_tg VARCHAR(255) NOT NULL UNIQUE, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TRIGGER update_hackathon_team_updated_at | ||
BEFORE UPDATE | ||
ON hackathon_team_2024 | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_timestamp(); | ||
|
||
-- Users Table | ||
CREATE TABLE hackathon_user_2024 | ||
( | ||
id SERIAL PRIMARY KEY, | ||
first_name VARCHAR(50) NOT NULL, | ||
last_name VARCHAR(50) NOT NULL, | ||
phone VARCHAR(20) NOT NULL UNIQUE, | ||
nickname_tg VARCHAR(255) NOT NULL UNIQUE, | ||
university_id INT, | ||
team_id INT, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
CONSTRAINT fk_university FOREIGN KEY (university_id) REFERENCES hackathon_university_2024 (id) ON DELETE SET NULL, | ||
CONSTRAINT fk_team FOREIGN KEY (team_id) REFERENCES hackathon_team_2024 (id) ON DELETE SET NULL | ||
); | ||
|
||
CREATE TRIGGER update_hackathon_updated_at | ||
BEFORE UPDATE ON hackathon | ||
CREATE TRIGGER update_hackathon_user_updated_at | ||
BEFORE UPDATE | ||
ON hackathon_user_2024 | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_timestamp(); | ||
|
||
-- Trigger to Increment Team Member Count | ||
CREATE | ||
OR REPLACE FUNCTION increment_team_member_count() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
UPDATE hackathon_team_2024 | ||
SET count_members = count_members + 1 | ||
WHERE id = NEW.team_id; | ||
RETURN NEW; | ||
END; | ||
$$ | ||
LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER increment_team_member_trigger | ||
AFTER INSERT | ||
ON hackathon_user_2024 | ||
FOR EACH ROW | ||
EXECUTE FUNCTION increment_team_member_count(); | ||
|
||
-- News Table | ||
CREATE TABLE news ( | ||
id SERIAL PRIMARY KEY, | ||
description TEXT NOT NULL, | ||
preview_id INT, | ||
header VARCHAR(255) NOT NULL, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
CREATE TABLE news | ||
( | ||
id SERIAL PRIMARY KEY, | ||
description TEXT NOT NULL, | ||
preview_id INT, | ||
header VARCHAR(255) NOT NULL, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TRIGGER update_news_updated_at | ||
BEFORE UPDATE ON news | ||
BEFORE UPDATE | ||
ON news | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_timestamp(); | ||
|
||
-- News Media Table | ||
CREATE TABLE news_media ( | ||
id SERIAL PRIMARY KEY, | ||
src_url TEXT NOT NULL, | ||
news_id INT REFERENCES news(id) ON DELETE CASCADE, | ||
type_media type_media NOT NULL, | ||
position INT NOT NULL, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
CREATE TABLE news_media | ||
( | ||
id SERIAL PRIMARY KEY, | ||
src_url TEXT NOT NULL, | ||
news_id INT REFERENCES news (id) ON DELETE CASCADE, | ||
type_media type_media NOT NULL, | ||
position INT NOT NULL, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TRIGGER update_news_media_updated_at | ||
BEFORE UPDATE ON news_media | ||
BEFORE UPDATE | ||
ON news_media | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_timestamp(); | ||
|
||
-- Announcement Banner Table | ||
CREATE TABLE announcement_banner ( | ||
id SERIAL PRIMARY KEY, | ||
src_url TEXT NOT NULL, | ||
type_media type_media NOT NULL, | ||
description VARCHAR(255) NOT NULL, | ||
showing BOOLEAN NOT NULL DEFAULT FALSE, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
CREATE TABLE announcement_banner | ||
( | ||
id SERIAL PRIMARY KEY, | ||
src_url TEXT NOT NULL, | ||
type_media type_media NOT NULL, | ||
description VARCHAR(255) NOT NULL, | ||
showing BOOLEAN NOT NULL DEFAULT FALSE, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TRIGGER update_announcement_banner_updated_at | ||
BEFORE UPDATE ON announcement_banner | ||
BEFORE UPDATE | ||
ON announcement_banner | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_timestamp(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
migrations/2025-01-05-165244_add_email_to_hackathon_team_2024/down.sql
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
migrations/2025-01-05-165244_add_email_to_hackathon_team_2024/up.sql
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
migrations/2025-01-05-202614_add_team_trigger_count_member/down.sql
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
migrations/2025-01-05-202614_add_team_trigger_count_member/up.sql
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod get; | ||
pub mod post; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Oops, something went wrong.