Merge pull request #5440 from wy65701436/fix-migration-scheme

Add default value for creation time and update time trigger
This commit is contained in:
Daniel Jiang 2018-08-01 09:57:15 +08:00 committed by GitHub
commit b37763c0bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,12 +31,27 @@ create table harbor_user (
reset_uuid varchar(40) DEFAULT NULL,
salt varchar(40) DEFAULT NULL,
sysadmin_flag smallint DEFAULT 0 NOT NULL,
creation_time timestamp,
update_time timestamp,
creation_time timestamp default CURRENT_TIMESTAMP,
update_time timestamp default CURRENT_TIMESTAMP,
UNIQUE (username),
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 (
project_id int PRIMARY KEY NOT NULL,
owner_id int NOT NULL,
@ -45,8 +60,8 @@ create table project (
and 11 is reserved for marking the deleted project.
*/
name varchar (255) NOT NULL,
creation_time timestamp,
update_time timestamp,
creation_time timestamp default CURRENT_TIMESTAMP,
update_time timestamp default CURRENT_TIMESTAMP,
deleted smallint DEFAULT 0 NOT NULL,
/*
FOREIGN KEY (owner_id) REFERENCES harbor_user(user_id),
@ -54,6 +69,8 @@ create table project (
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 (
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)
);
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 table project_metadata (
@ -118,7 +126,7 @@ create table access_log (
repo_tag varchar (128),
GUID varchar(64),
operation varchar(20) NOT NULL,
op_time timestamp,
op_time timestamp default CURRENT_TIMESTAMP,
primary key (log_id)
);