Skip to content

Commit

Permalink
Merge pull request #31 from CMIPT/zzq-database-update
Browse files Browse the repository at this point in the history
Update the primary key of database
  • Loading branch information
ajiankexx authored Aug 21, 2024
2 parents 0525f56 + a24a088 commit 367eca5
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 60 deletions.
20 changes: 7 additions & 13 deletions database/constraint/all_column_constraint.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
-- The constarint of the primary key and unique key is added to the table.
ALTER TABLE ONLY public.t_repository
ADD CONSTRAINT pk_repository PRIMARY KEY (pk_repository_id);
ALTER TABLE ONLY public.t_repository
ADD CONSTRAINT pk_repository PRIMARY KEY (id);

-- The constraint of t_user is added to the table.
ALTER TABLE ONLY public.t_user
ADD CONSTRAINT pk_user_table PRIMARY KEY (pk_user_id);
ALTER TABLE ONLY public.t_user
ADD CONSTRAINT pk_user_table PRIMARY KEY (id);

ALTER TABLE ONLY public.t_user
ADD CONSTRAINT users_email_key UNIQUE (email);

ALTER TABLE ONLY public.t_user
ADD CONSTRAINT users_username_key UNIQUE (username);

-- The constraint of t_user_repository is not necessary,
-- The constraint of t_user_repository is not necessary,
-- as the primary key is already unique.
ALTER TABLE ONLY public.t_user_repository
ADD CONSTRAINT pk_user_repository PRIMARY KEY (pk_user_repository_id);
ALTER TABLE ONLY public.t_user_repository
ADD CONSTRAINT pk_user_repository PRIMARY KEY (id);
2 changes: 1 addition & 1 deletion database/database_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DB_PORT=$4
DB_PASSWORD=$5
# Set the root directory where the SQL files are located
ROOT_DIR="database"
SUB_DIR_SEQUENCE=(sequence table constraint function trigger)
SUB_DIR_SEQUENCE=(table constraint function trigger)

TEMP_SQL_FILE="temp_sql_script.sql"

Expand Down
10 changes: 5 additions & 5 deletions database/diagram/gcs_back_end.drawio
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" version="24.7.6">
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0" version="24.7.7">
<diagram id="R2lEEEUBdFMjLlhIrx00" name="Page-1">
<mxGraphModel dx="3248" dy="942" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0" extFonts="Permanent Marker^https://fonts.googleapis.com/css?family=Permanent+Marker">
<mxGraphModel dx="2755" dy="1011" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0" extFonts="Permanent Marker^https://fonts.googleapis.com/css?family=Permanent+Marker">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
Expand Down Expand Up @@ -37,7 +37,7 @@
<mxRectangle width="30" height="30" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="6WugjG2xhQJgWSEuV__S-108" value="pk_repository_id bigint DEFAULT nextval(&#39;public.repositories_id_seq&#39;::regclass) NOT NULL" style="shape=partialRectangle;overflow=hidden;connectable=0;fillColor=none;align=left;strokeColor=inherit;top=0;left=0;bottom=0;right=0;spacingLeft=6;" parent="6WugjG2xhQJgWSEuV__S-106" vertex="1">
<mxCell id="6WugjG2xhQJgWSEuV__S-108" value="id bigint NOT NULL" style="shape=partialRectangle;overflow=hidden;connectable=0;fillColor=none;align=left;strokeColor=inherit;top=0;left=0;bottom=0;right=0;spacingLeft=6;" parent="6WugjG2xhQJgWSEuV__S-106" vertex="1">
<mxGeometry x="30" width="520" height="30" as="geometry">
<mxRectangle width="520" height="30" as="alternateBounds" />
</mxGeometry>
Expand Down Expand Up @@ -248,7 +248,7 @@
<mxRectangle width="30" height="30" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="6WugjG2xhQJgWSEuV__S-157" value="pk_user_id bigint DEFAULT nextval(&#39;public.users_id_seq&#39;::regclass) NOT NULL" style="shape=partialRectangle;overflow=hidden;connectable=0;fillColor=none;align=left;strokeColor=inherit;top=0;left=0;bottom=0;right=0;spacingLeft=6;" parent="6WugjG2xhQJgWSEuV__S-155" vertex="1">
<mxCell id="6WugjG2xhQJgWSEuV__S-157" value="id bigint NOT NULL" style="shape=partialRectangle;overflow=hidden;connectable=0;fillColor=none;align=left;strokeColor=inherit;top=0;left=0;bottom=0;right=0;spacingLeft=6;" parent="6WugjG2xhQJgWSEuV__S-155" vertex="1">
<mxGeometry x="30" width="510" height="30" as="geometry">
<mxRectangle width="510" height="30" as="alternateBounds" />
</mxGeometry>
Expand Down Expand Up @@ -355,7 +355,7 @@
<mxRectangle width="30" height="30" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="6WugjG2xhQJgWSEuV__S-182" value="pk_user_repository_id bigint DEFAULT nextval(&#39;public.user_repository_id_seq&#39;::regclass) NOT NULL" style="shape=partialRectangle;overflow=hidden;connectable=0;fillColor=none;align=left;strokeColor=inherit;top=0;left=0;bottom=0;right=0;spacingLeft=6;" parent="6WugjG2xhQJgWSEuV__S-180" vertex="1">
<mxCell id="6WugjG2xhQJgWSEuV__S-182" value="id bigint NOT NULL" style="shape=partialRectangle;overflow=hidden;connectable=0;fillColor=none;align=left;strokeColor=inherit;top=0;left=0;bottom=0;right=0;spacingLeft=6;" parent="6WugjG2xhQJgWSEuV__S-180" vertex="1">
<mxGeometry x="30" width="570" height="30" as="geometry">
<mxRectangle width="570" height="30" as="alternateBounds" />
</mxGeometry>
Expand Down
Binary file modified database/diagram/gcs_back_end.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions database/function/update_gmt_updated_column.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE FUNCTION public.update_gmt_updated_column()
RETURNS trigger
CREATE FUNCTION public.update_gmt_updated_column()
RETURNS trigger
LANGUAGE plpgsql AS $$
BEGIN
BEGIN
NEW.gmt_updated = CURRENT_TIMESTAMP;
RETURN NEW;
END;
Expand Down
5 changes: 0 additions & 5 deletions database/sequence/all_column_seq.sql

This file was deleted.

3 changes: 0 additions & 3 deletions database/sequence/sequence_set.sql

This file was deleted.

22 changes: 11 additions & 11 deletions database/table/t_repository.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
CREATE TABLE public.t_repository (
pk_repository_id bigint DEFAULT nextval('public.repositories_id_seq'::regclass) NOT NULL,
repository_name character varying(255) NOT NULL,
repository_description character varying(255) NOT NULL,
is_private boolean DEFAULT false,
user_id bigint NOT NULL,
id bigint NOT NULL,
repository_name character varying(255) NOT NULL,
repository_description character varying(255) NOT NULL,
is_private boolean DEFAULT false,
user_id bigint NOT NULL,
star integer DEFAULT 0 NOT NULL,
fork integer DEFAULT 0 NOT NULL,
watcher integer DEFAULT 0 NOT NULL,
gmt_created timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_updated timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
fork integer DEFAULT 0 NOT NULL,
watcher integer DEFAULT 0 NOT NULL,
gmt_created timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_updated timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_deleted timestamp without time zone
);

COMMENT ON TABLE public.t_repository IS 'Table for storing repository information.';

COMMENT ON COLUMN public.t_repository.pk_repository_id IS 'Primary key of the repository table.';
COMMENT ON COLUMN public.t_repository.id IS 'Primary key of the repository table.';
COMMENT ON COLUMN public.t_repository.repository_name IS 'Name of the repository.';
COMMENT ON COLUMN public.t_repository.repository_description IS 'Description of the repository.';
COMMENT ON COLUMN public.t_repository.is_private IS 'Indicates if the repository is private.';
COMMENT ON COLUMN public.t_repository.user_id IS 'ID of the user who owns the repository.';
COMMENT ON COLUMN public.t_repository.gmt_created IS 'Timestamp when the repository was created.';
COMMENT ON COLUMN public.t_repository.gmt_updated IS 'Timestamp when the repository was last updated.';
COMMENT ON COLUMN public.t_repository.gmt_deleted IS 'Timestamp when the repository was deleted.
COMMENT ON COLUMN public.t_repository.gmt_deleted IS 'Timestamp when the repository was deleted.
If set to NULL, it indicates that the repository has not been deleted.';
14 changes: 7 additions & 7 deletions database/table/t_user.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
CREATE TABLE public.t_user (
pk_user_id bigint DEFAULT nextval('public.users_id_seq'::regclass) NOT NULL,
username character varying(50) NOT NULL,
email character varying(254) NOT NULL,
user_password character(128) NOT NULL,
gmt_created timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_updated timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
id bigint NOT NULL,
username character varying(50) NOT NULL,
email character varying(254) NOT NULL,
user_password character(128) NOT NULL,
gmt_created timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_updated timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_deleted timestamp without time zone
);

COMMENT ON TABLE public.t_user IS 'Table for storing user information.';

COMMENT ON COLUMN public.t_user.pk_user_id IS 'Primary key of the user table.';
COMMENT ON COLUMN public.t_user.id IS 'Primary key of the user table.';
COMMENT ON COLUMN public.t_user.username IS 'Username of the user.';
COMMENT ON COLUMN public.t_user.email IS 'Email address of the user.';
COMMENT ON COLUMN public.t_user.user_password IS 'Password of the user, stored as an MD5 hash.';
Expand Down
12 changes: 6 additions & 6 deletions database/table/t_user_repository.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
CREATE TABLE public.t_user_repository (
pk_user_repository_id bigint DEFAULT nextval('public.user_repository_id_seq'::regclass) NOT NULL,
user_id bigint NOT NULL,
repository_id bigint NOT NULL,
gmt_created timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_updated timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
id bigint NOT NULL,
user_id bigint NOT NULL,
repository_id bigint NOT NULL,
gmt_created timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_updated timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
gmt_deleted timestamp without time zone
);

COMMENT ON TABLE public.t_user_repository IS 'Table for storing relationships between users and repositories.';

COMMENT ON COLUMN public.t_user_repository.pk_user_repository_id IS 'Primary key of the user_repository table.';
COMMENT ON COLUMN public.t_user_repository.id IS 'Primary key of the user_repository table.';
COMMENT ON COLUMN public.t_user_repository.user_id IS 'ID of the user.';
COMMENT ON COLUMN public.t_user_repository.repository_id IS 'ID of the repository.';
COMMENT ON COLUMN public.t_user_repository.gmt_created IS 'Timestamp when the relationship was created.';
Expand Down
12 changes: 6 additions & 6 deletions database/trigger/all_table_trigger.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-- The trigger is added to the table.

-- The trigger of the t_repository table is added.
CREATE TRIGGER update_t_repository_gmt_updated
BEFORE UPDATE ON public.t_repository
CREATE TRIGGER update_t_repository_gmt_updated
BEFORE UPDATE ON public.t_repository
FOR EACH ROW EXECUTE FUNCTION public.update_gmt_updated_column();

-- The trigger of the t_user table is added.
CREATE TRIGGER update_t_user_gmt_updated
BEFORE UPDATE ON public.t_user
CREATE TRIGGER update_t_user_gmt_updated
BEFORE UPDATE ON public.t_user
FOR EACH ROW EXECUTE FUNCTION public.update_gmt_updated_column();

-- The trigger of the t_user_repository table is added.
CREATE TRIGGER update_t_user_repository_gmt_updated
BEFORE UPDATE ON public.t_user_repository
CREATE TRIGGER update_t_user_repository_gmt_updated
BEFORE UPDATE ON public.t_user_repository
FOR EACH ROW EXECUTE FUNCTION public.update_gmt_updated_column();

0 comments on commit 367eca5

Please sign in to comment.