Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
feat: tables for course (eesast#176)
Browse files Browse the repository at this point in the history
* feat: tables for course

* fix(ci)
  • Loading branch information
FranGuam authored May 17, 2024
1 parent f3afa6b commit 7822fd4
Show file tree
Hide file tree
Showing 41 changed files with 546 additions and 17 deletions.
468 changes: 451 additions & 17 deletions metadata/tables.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."share_course" alter column "year" set default '2000';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "public"."share_course" ALTER COLUMN "year" drop default;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course" rename to "share_course";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."share_course" rename to "course";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."course_manager";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "public"."course_manager" ("user" uuid NOT NULL, PRIMARY KEY ("user") , FOREIGN KEY ("user") REFERENCES "public"."users"("uuid") ON UPDATE restrict ON DELETE cascade, UNIQUE ("user"));COMMENT ON TABLE "public"."course_manager" IS E'课程共享平台的管理员';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."course_info";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "public"."course_info" ("course_id" uuid NOT NULL, "key" text NOT NULL, "value" text, PRIMARY KEY ("course_id","key") , FOREIGN KEY ("course_id") REFERENCES "public"."course"("uuid") ON UPDATE restrict ON DELETE cascade);COMMENT ON TABLE "public"."course_info" IS E'课程信息键值对表,对manager开放编辑';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."course_comment";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE "public"."course_comment" ("uuid" uuid NOT NULL DEFAULT gen_random_uuid(), "course" uuid NOT NULL, "user" uuid NOT NULL, "comment" text NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("uuid") , FOREIGN KEY ("course") REFERENCES "public"."course"("uuid") ON UPDATE restrict ON DELETE cascade, FOREIGN KEY ("user") REFERENCES "public"."users"("uuid") ON UPDATE restrict ON DELETE cascade, UNIQUE ("uuid"));COMMENT ON TABLE "public"."course_comment" IS E'用户评论表';
CREATE EXTENSION IF NOT EXISTS pgcrypto;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_info" rename column "course" to "course_id";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_info" rename column "course_id" to "course";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."course_rating";
17 changes: 17 additions & 0 deletions migrations/1715865468541_create_table_public_course_rating/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE "public"."course_rating" ("course" uuid NOT NULL, "user" uuid NOT NULL, "dim1" integer NOT NULL, "dim2" integer NOT NULL, "dim3" integer NOT NULL, "dim4" integer NOT NULL, "dim5" integer NOT NULL, "dim6" integer NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("course","user") , FOREIGN KEY ("course") REFERENCES "public"."course"("uuid") ON UPDATE restrict ON DELETE cascade, FOREIGN KEY ("user") REFERENCES "public"."users"("uuid") ON UPDATE restrict ON DELETE cascade);COMMENT ON TABLE "public"."course_rating" IS E'用户评分表';
CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
RETURNS TRIGGER AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "set_public_course_rating_updated_at"
BEFORE UPDATE ON "public"."course_rating"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_course_rating_updated_at" ON "public"."course_rating"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim1" is NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim1" is E'任务量';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim2" is NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim2" is E'内容难度';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim3" is NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim3" is E'上课质量';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim4" is NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim4" is E'收获感';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim5" is NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim5" is E'给分好坏';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim6" is NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment on column "public"."course_rating"."dim6" is E'考试作业讲课相关度';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_comment" rename column "course_id" to "course";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_comment" rename column "course" to "course_id";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_comment" rename column "user_uuid" to "user";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_comment" rename column "user" to "user_uuid";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_info" rename column "course_id" to "course";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_info" rename column "course" to "course_id";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_manager" rename column "user_uuid" to "user";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_manager" rename column "user" to "user_uuid";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_rating" rename column "course_id" to "course";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_rating" rename column "course" to "course_id";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_rating" rename column "user_uuid" to "user";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."course_rating" rename column "user" to "user_uuid";
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."course_comment" add column "updated_at" timestamptz
-- null default now();
--
-- CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
-- RETURNS TRIGGER AS $$
-- DECLARE
-- _new record;
-- BEGIN
-- _new := NEW;
-- _new."updated_at" = NOW();
-- RETURN _new;
-- END;
-- $$ LANGUAGE plpgsql;
-- CREATE TRIGGER "set_public_course_comment_updated_at"
-- BEFORE UPDATE ON "public"."course_comment"
-- FOR EACH ROW
-- EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
-- COMMENT ON TRIGGER "set_public_course_comment_updated_at" ON "public"."course_comment"
-- IS 'trigger to set value of column "updated_at" to current timestamp on row update';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
alter table "public"."course_comment" add column "updated_at" timestamptz
null default now();

CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
RETURNS TRIGGER AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "set_public_course_comment_updated_at"
BEFORE UPDATE ON "public"."course_comment"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_course_comment_updated_at" ON "public"."course_comment"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';

0 comments on commit 7822fd4

Please sign in to comment.