debug and create new table
This commit is contained in:
parent
fc24f202ef
commit
fadb41922a
@ -14,7 +14,7 @@ EOSQL
|
||||
|
||||
function import_dump() {
|
||||
local database=$1
|
||||
psql -U "$POSTGRES_USER" -d "$database" -a -f "docker-entrypoint-initdb.d/$database.sql"
|
||||
psql -U "$POSTGRES_USER" -d "$database" -a -f "docker-entrypoint-initdb.d/dumps/$database.sql"
|
||||
}
|
||||
|
||||
if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
|
||||
|
@ -57,6 +57,42 @@ ALTER SEQUENCE public.blog_id_seq OWNER TO postgres;
|
||||
ALTER SEQUENCE public.blog_id_seq OWNED BY public.blog.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: comment; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.comment (
|
||||
id integer NOT NULL,
|
||||
text character varying NOT NULL,
|
||||
author_id integer NOT NULL,
|
||||
post_id integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.comment OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: comment_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.comment_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.comment_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: comment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.comment_id_seq OWNED BY public.comment.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
@ -136,6 +172,13 @@ ALTER SEQUENCE public.user_id_seq OWNED BY public."user".id;
|
||||
ALTER TABLE ONLY public.blog ALTER COLUMN id SET DEFAULT nextval('public.blog_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: comment id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.comment ALTER COLUMN id SET DEFAULT nextval('public.comment_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
@ -158,6 +201,15 @@ INSERT INTO public.blog (id, owner_id, name, description) VALUES (2, 1, 'мой
|
||||
INSERT INTO public.blog (id, owner_id, name, description) VALUES (3, 2, 'мой старый блог', 'такое же описание');
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: comment; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
INSERT INTO public.comment (id, text, author_id, post_id) VALUES (1, 'хороший пост', 1, 1);
|
||||
INSERT INTO public.comment (id, text, author_id, post_id) VALUES (2, 'тоже норм', 1, 2);
|
||||
INSERT INTO public.comment (id, text, author_id, post_id) VALUES (3, 'другой комент', 2, 2);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: post; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
@ -181,6 +233,13 @@ INSERT INTO public."user" (id, email, login) VALUES (2, 'another@gmail.com', 'an
|
||||
SELECT pg_catalog.setval('public.blog_id_seq', 3, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: comment_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.comment_id_seq', 3, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
@ -203,6 +262,14 @@ ALTER TABLE ONLY public.blog
|
||||
ADD CONSTRAINT blog_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: comment comment_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.comment
|
||||
ADD CONSTRAINT comment_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post post_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
@ -227,6 +294,22 @@ ALTER TABLE ONLY public.blog
|
||||
ADD CONSTRAINT blog_owner_id_fkey FOREIGN KEY (owner_id) REFERENCES public."user"(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: comment comment_author_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.comment
|
||||
ADD CONSTRAINT comment_author_id_fkey FOREIGN KEY (author_id) REFERENCES public."user"(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: comment comment_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.comment
|
||||
ADD CONSTRAINT comment_post_id_fkey FOREIGN KEY (post_id) REFERENCES public.post(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post post_author_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
@ -1,5 +1,6 @@
|
||||
from .db1.user import User as User
|
||||
from .db1.blog import Blog as Blog
|
||||
from .db1.post import Post as Post
|
||||
from .db1.comment import Comment as Comment
|
||||
|
||||
from .db2.log import Log as Log
|
||||
|
16
src/adapters/database/models/db1/comment.py
Normal file
16
src/adapters/database/models/db1/comment.py
Normal file
@ -0,0 +1,16 @@
|
||||
from sqlalchemy import INTEGER, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from .base import Base
|
||||
from .user import User
|
||||
from .post import Post
|
||||
|
||||
|
||||
class Comment(Base):
|
||||
__tablename__ = "comment"
|
||||
id: Mapped[int] = mapped_column(INTEGER, primary_key=True, autoincrement=True)
|
||||
text: Mapped[str]
|
||||
author_id: Mapped[int] = mapped_column(ForeignKey(User.id))
|
||||
# author: Mapped[User] = relationship(lazy="selectin")
|
||||
post_id: Mapped[int] = mapped_column(ForeignKey(Post.id))
|
||||
# post: Mapped[Post] = relationship(lazy="selectin")
|
Loading…
x
Reference in New Issue
Block a user