fintual-backend-devops-go / go-service / schema.sql
schema.sql
Raw
-- Derived from: python manage.py sqlmigrate blog 0001 at original b74e8ed.
-- No Django auth/admin tables are needed by the eight application endpoints.
BEGIN;
CREATE TABLE blog_tag (id bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, name varchar(64) NOT NULL UNIQUE, slug varchar(64) NOT NULL UNIQUE, created_at timestamptz NOT NULL);
CREATE TABLE blog_user (id bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, username varchar(64) NOT NULL UNIQUE, email varchar(255) NOT NULL, display_name varchar(128) NOT NULL, bio text NOT NULL, created_at timestamptz NOT NULL);
CREATE TABLE blog_post (id bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, title varchar(255) NOT NULL, body text NOT NULL, is_published boolean NOT NULL, view_count integer NOT NULL, created_at timestamptz NOT NULL, updated_at timestamptz NOT NULL, author_id bigint NOT NULL);
CREATE TABLE blog_post_tags (id bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, post_id bigint NOT NULL, tag_id bigint NOT NULL);
CREATE TABLE blog_comment (id bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, body text NOT NULL, created_at timestamptz NOT NULL, post_id bigint NOT NULL, author_id bigint NOT NULL);
CREATE INDEX blog_tag_name_c5718cc8_like ON blog_tag (name varchar_pattern_ops);
CREATE INDEX blog_tag_slug_01068d0e_like ON blog_tag (slug varchar_pattern_ops);
CREATE INDEX blog_user_username_5f75df34_like ON blog_user (username varchar_pattern_ops);
ALTER TABLE blog_post ADD CONSTRAINT blog_post_author_id_dd7a8485_fk_blog_user_id FOREIGN KEY (author_id) REFERENCES blog_user(id) DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX blog_post_author_id_dd7a8485 ON blog_post(author_id);
ALTER TABLE blog_post_tags ADD CONSTRAINT blog_post_tags_post_id_tag_id_4925ec37_uniq UNIQUE(post_id,tag_id);
ALTER TABLE blog_post_tags ADD CONSTRAINT blog_post_tags_post_id_a1c71c8a_fk_blog_post_id FOREIGN KEY(post_id) REFERENCES blog_post(id) DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE blog_post_tags ADD CONSTRAINT blog_post_tags_tag_id_0875c551_fk_blog_tag_id FOREIGN KEY(tag_id) REFERENCES blog_tag(id) DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX blog_post_tags_post_id_a1c71c8a ON blog_post_tags(post_id);
CREATE INDEX blog_post_tags_tag_id_0875c551 ON blog_post_tags(tag_id);
ALTER TABLE blog_comment ADD CONSTRAINT blog_comment_post_id_580e96ef_fk_blog_post_id FOREIGN KEY(post_id) REFERENCES blog_post(id) DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE blog_comment ADD CONSTRAINT blog_comment_author_id_4f11e2e0_fk_blog_user_id FOREIGN KEY(author_id) REFERENCES blog_user(id) DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX blog_comment_post_id_580e96ef ON blog_comment(post_id);
CREATE INDEX blog_comment_author_id_4f11e2e0 ON blog_comment(author_id);
COMMIT;