mirror of
https://github.com/goharbor/harbor
synced 2025-04-21 18:30:26 +00:00
Merge pull request #5440 from wy65701436/fix-migration-scheme
Add default value for creation time and update time trigger
This commit is contained in:
commit
b37763c0bd
@ -31,12 +31,27 @@ create table harbor_user (
|
|||||||
reset_uuid varchar(40) DEFAULT NULL,
|
reset_uuid varchar(40) DEFAULT NULL,
|
||||||
salt varchar(40) DEFAULT NULL,
|
salt varchar(40) DEFAULT NULL,
|
||||||
sysadmin_flag smallint DEFAULT 0 NOT NULL,
|
sysadmin_flag smallint DEFAULT 0 NOT NULL,
|
||||||
creation_time timestamp,
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
||||||
update_time timestamp,
|
update_time timestamp default CURRENT_TIMESTAMP,
|
||||||
UNIQUE (username),
|
UNIQUE (username),
|
||||||
UNIQUE (email)
|
UNIQUE (email)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE FUNCTION update_update_time_at_column() RETURNS trigger
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
NEW.update_time = NOW();
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
/*
|
||||||
|
The trigger for harbor_user and project should be added by alembic pgsql v1.6.0,
|
||||||
|
put them here is to reduce DB operation, make all things be done in the creation of DB.
|
||||||
|
*/
|
||||||
|
CREATE TRIGGER harbor_user_update_time_at_modtime BEFORE UPDATE ON harbor_user FOR EACH ROW EXECUTE PROCEDURE update_update_time_at_column();
|
||||||
|
|
||||||
create table project (
|
create table project (
|
||||||
project_id int PRIMARY KEY NOT NULL,
|
project_id int PRIMARY KEY NOT NULL,
|
||||||
owner_id int NOT NULL,
|
owner_id int NOT NULL,
|
||||||
@ -45,8 +60,8 @@ create table project (
|
|||||||
and 11 is reserved for marking the deleted project.
|
and 11 is reserved for marking the deleted project.
|
||||||
*/
|
*/
|
||||||
name varchar (255) NOT NULL,
|
name varchar (255) NOT NULL,
|
||||||
creation_time timestamp,
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
||||||
update_time timestamp,
|
update_time timestamp default CURRENT_TIMESTAMP,
|
||||||
deleted smallint DEFAULT 0 NOT NULL,
|
deleted smallint DEFAULT 0 NOT NULL,
|
||||||
/*
|
/*
|
||||||
FOREIGN KEY (owner_id) REFERENCES harbor_user(user_id),
|
FOREIGN KEY (owner_id) REFERENCES harbor_user(user_id),
|
||||||
@ -54,6 +69,8 @@ create table project (
|
|||||||
UNIQUE (name)
|
UNIQUE (name)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TRIGGER project_update_time_at_modtime BEFORE UPDATE ON project FOR EACH ROW EXECUTE PROCEDURE update_update_time_at_column();
|
||||||
|
|
||||||
create table project_member (
|
create table project_member (
|
||||||
id int NOT NULL,
|
id int NOT NULL,
|
||||||
project_id int NOT NULL,
|
project_id int NOT NULL,
|
||||||
@ -70,15 +87,6 @@ create table project_member (
|
|||||||
CONSTRAINT unique_project_entity_type UNIQUE (project_id, entity_id, entity_type)
|
CONSTRAINT unique_project_entity_type UNIQUE (project_id, entity_id, entity_type)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE FUNCTION update_update_time_at_column() RETURNS trigger
|
|
||||||
LANGUAGE plpgsql
|
|
||||||
AS $$
|
|
||||||
BEGIN
|
|
||||||
NEW.update_time = NOW();
|
|
||||||
RETURN NEW;
|
|
||||||
END;
|
|
||||||
$$;
|
|
||||||
|
|
||||||
CREATE TRIGGER project_member_update_time_at_modtime BEFORE UPDATE ON project_member FOR EACH ROW EXECUTE PROCEDURE update_update_time_at_column();
|
CREATE TRIGGER project_member_update_time_at_modtime BEFORE UPDATE ON project_member FOR EACH ROW EXECUTE PROCEDURE update_update_time_at_column();
|
||||||
|
|
||||||
create table project_metadata (
|
create table project_metadata (
|
||||||
@ -118,7 +126,7 @@ create table access_log (
|
|||||||
repo_tag varchar (128),
|
repo_tag varchar (128),
|
||||||
GUID varchar(64),
|
GUID varchar(64),
|
||||||
operation varchar(20) NOT NULL,
|
operation varchar(20) NOT NULL,
|
||||||
op_time timestamp,
|
op_time timestamp default CURRENT_TIMESTAMP,
|
||||||
primary key (log_id)
|
primary key (log_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user