Skip to content

Commit 78a0fbe

Browse files
committed
app.post runs but not blueprints
1 parent 0f2a3ff commit 78a0fbe

26 files changed

+1269
-241
lines changed

Pipfile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@ name = "pypi"
77
flask-healthz = "*"
88
marshmallow = "*"
99
python-dotenv = "*"
10-
Flask-SQLAlchemy = "*"
11-
Flask-Migrate = "*"
12-
Flask-Script = "*"
1310
Quart-CORS = "*"
14-
Flask-Bcrypt = "*"
1511
PyJWT = "*"
1612
alembic = "*"
1713
itsdangerous = "*"
18-
flask-oidc = {ref = "refs/pull/144/head", git = "https://github.com/puiterwijk/flask-oidc.git"}
1914
quart = "*"
2015
quart-wtforms = "*"
21-
quart-flask-patch = "*"
2216
aioquic = "*"
2317
psycopg-pool = "*"
2418
psycopg = {extras = ["binary"], version = "*"}
25-
hypercorn = {extras = ["h3"], version = "*"}
2619
quart-trio = "*"
2720
jsonpickle = "*"
21+
quart-bcrypt = "*"
22+
quart-sqlalchemy = "*"
23+
quart-keycloak = "*"
24+
hypercorn = {extras = ["h3", "trio"], version = "*"}
2825

2926
[dev-packages]
3027
pytest-flask = "*"

Pipfile.lock

Lines changed: 700 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ $ pipenv install --python=/path/to/python
4747
## Database Migration
4848

4949
- Copy `env.py` to `migrations/` folder.
50-
- Set the values -f `DB_foo` in `/etc/pythonrestapi_config.json`
50+
- Set the values `DB_foo` in `/etc/pythonrestapi_config.json`
5151
- run migrations initialization with db init command:
5252

5353
```
5454
$ pipenv run alembic init migrations
55+
$ cp env.py migrations
5556
$ pipenv run alembic revision --autogenerate -m "Initial migration"
5657
$ pipenv run alembic upgrade head
5758
```

env.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Copy this file to migrations/env.py
22
import os, sys, json, urllib
3-
from urllib.parse import quote
3+
from dotenv import load_dotenv
4+
from urllib import parse
45
from logging.config import fileConfig
56
from urllib.parse import unquote
6-
from sqlalchemy import engine_from_config
7-
from sqlalchemy import pool
8-
7+
from sqlalchemy import engine_from_config, pool, FetchedValue
98
from alembic import context
10-
9+
load_dotenv()
1110
# this is the Alembic Config object, which provides
1211
# access to the values within the .ini file in use.
1312
f = open("/etc/pythonrestapi_config.json", "r")
@@ -22,17 +21,24 @@
2221
# for 'autogenerate' support
2322
# from myapp import mymodel
2423
# target_metadata = mymodel.Base.metadata
25-
from src.models import LibraryMetadata
26-
target_metadata = LibraryMetadata
24+
from src.models.base import Base
25+
from src.models.AuthorModel import AuthorModel
26+
from src.models.BookModel import BookModel
27+
from src.models.UserModel import UserModel
28+
29+
target_metadata = Base.metadata
30+
31+
#from src.models.Database import LibraryMetadata
32+
#target_metadata = LibraryMetadata
2733

2834
# other values from the config, defined by the needs of env.py,
2935
# can be acquired:
3036
# my_important_option = config.get_main_option("my_important_option")
3137
# ... etc.
3238
section = config.config_ini_section
33-
print(f"password: {json_config['DB_PASSWORD']}, host: {json_config['DB_HOST']}, db: {json_config['DB_DATABASE']}")
34-
config.set_section_option(section, "DB_USERNAME", json_config["DB_USERNAME"])
35-
config.set_section_option(section, "DB_PASSWORD", urllib.parse.quote_plus(json_config['DB_PASSWORD']).replace("%", "%%"))
39+
print(f"password: {os.environ.get('DB_PASSWORD')}, host: {json_config['DB_HOST']}, db: {json_config['DB_DATABASE']}")
40+
config.set_section_option(section, "DB_USERNAME", os.environ.get('DB_USERNAME'))
41+
config.set_section_option(section, "DB_PASSWORD", urllib.parse.quote_plus(os.environ.get('DB_PASSWORD')).replace("%", "%%"))
3642
config.set_section_option(section, "DB_HOST", json_config["DB_HOST"])
3743
config.set_section_option(section, "DB_DATABASE", json_config["DB_DATABASE"])
3844
def run_migrations_offline() -> None:

quart.sh renamed to hypercorn.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
rm -f /tmp/server.*
33
openssl req -new -newkey rsa:4096 -x509 -nodes -days 365 -keyout /tmp/server.key -out /tmp/server.crt -subj "/C=SG/ST=Singapore/L=Singapore /O=Kok How Pte. Ltd./OU=PythonFlaskRestAPI/CN=localhost/[email protected]" -passin pass:PythonFlaskRestAPI
44
pipenv run hypercorn --config=/etc/hypercorn.toml --reload src.main:app
5+
#pipenv run hypercorn --config=/etc/hypercorn.toml --reload 'src.main:create_app()'

library.sql

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
--
2+
-- PostgreSQL database dump
3+
--
4+
5+
-- Dumped from database version 17.4 (Debian 17.4-1.pgdg120+2)
6+
-- Dumped by pg_dump version 17.0 (Ubuntu 17.0-1.pgdg24.04+1)
7+
8+
SET statement_timeout = 0;
9+
SET lock_timeout = 0;
10+
SET idle_in_transaction_session_timeout = 0;
11+
SET transaction_timeout = 0;
12+
SET client_encoding = 'UTF8';
13+
SET standard_conforming_strings = on;
14+
SELECT pg_catalog.set_config('search_path', '', false);
15+
SET check_function_bodies = false;
16+
SET xmloption = content;
17+
SET client_min_messages = warning;
18+
SET row_security = off;
19+
20+
SET default_tablespace = '';
21+
22+
SET default_table_access_method = heap;
23+
24+
--
25+
-- Name: alembic_version; Type: TABLE; Schema: public; Owner: guest
26+
--
27+
28+
CREATE TABLE public.alembic_version (
29+
version_num character varying(32) NOT NULL
30+
);
31+
32+
33+
ALTER TABLE public.alembic_version OWNER TO guest;
34+
35+
--
36+
-- Name: authors; Type: TABLE; Schema: public; Owner: guest
37+
--
38+
39+
CREATE TABLE public.authors (
40+
id integer NOT NULL,
41+
firstname character varying(128) NOT NULL,
42+
lastname character varying(128) NOT NULL,
43+
email character varying(255) NOT NULL,
44+
phone character varying(15),
45+
created_at timestamp with time zone NOT NULL,
46+
modified_at timestamp with time zone NOT NULL
47+
);
48+
49+
50+
ALTER TABLE public.authors OWNER TO guest;
51+
52+
--
53+
-- Name: authors_id_seq; Type: SEQUENCE; Schema: public; Owner: guest
54+
--
55+
56+
ALTER TABLE public.authors ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
57+
SEQUENCE NAME public.authors_id_seq
58+
START WITH 1
59+
INCREMENT BY 1
60+
NO MINVALUE
61+
NO MAXVALUE
62+
CACHE 1
63+
);
64+
65+
66+
--
67+
-- Name: books; Type: TABLE; Schema: public; Owner: guest
68+
--
69+
70+
CREATE TABLE public.books (
71+
id integer NOT NULL,
72+
title character varying(128) NOT NULL,
73+
isbn character varying(255) NOT NULL,
74+
page_count integer NOT NULL,
75+
created_at timestamp with time zone NOT NULL,
76+
modified_at timestamp with time zone NOT NULL,
77+
author_id integer NOT NULL
78+
);
79+
80+
81+
ALTER TABLE public.books OWNER TO guest;
82+
83+
--
84+
-- Name: books_id_seq; Type: SEQUENCE; Schema: public; Owner: guest
85+
--
86+
87+
ALTER TABLE public.books ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
88+
SEQUENCE NAME public.books_id_seq
89+
START WITH 1
90+
INCREMENT BY 1
91+
NO MINVALUE
92+
NO MAXVALUE
93+
CACHE 1
94+
);
95+
96+
97+
--
98+
-- Name: users; Type: TABLE; Schema: public; Owner: guest
99+
--
100+
101+
CREATE TABLE public.users (
102+
id integer NOT NULL,
103+
firstname character varying(128) NOT NULL,
104+
lastname character varying(128) NOT NULL,
105+
email character varying(255) NOT NULL,
106+
phone character varying(15),
107+
password character varying(128),
108+
lastlogin timestamp with time zone,
109+
created_at timestamp with time zone NOT NULL,
110+
modified_at timestamp with time zone NOT NULL
111+
);
112+
113+
114+
ALTER TABLE public.users OWNER TO guest;
115+
116+
--
117+
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: guest
118+
--
119+
120+
ALTER TABLE public.users ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
121+
SEQUENCE NAME public.users_id_seq
122+
START WITH 1
123+
INCREMENT BY 1
124+
NO MINVALUE
125+
NO MAXVALUE
126+
CACHE 1
127+
);
128+
129+
130+
--
131+
-- Data for Name: alembic_version; Type: TABLE DATA; Schema: public; Owner: guest
132+
--
133+
134+
COPY public.alembic_version (version_num) FROM stdin;
135+
8813faeb5825
136+
\.
137+
138+
139+
--
140+
-- Data for Name: authors; Type: TABLE DATA; Schema: public; Owner: guest
141+
--
142+
143+
COPY public.authors (id, firstname, lastname, email, phone, created_at, modified_at) FROM stdin;
144+
\.
145+
146+
147+
--
148+
-- Data for Name: books; Type: TABLE DATA; Schema: public; Owner: guest
149+
--
150+
151+
COPY public.books (id, title, isbn, page_count, created_at, modified_at, author_id) FROM stdin;
152+
\.
153+
154+
155+
--
156+
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: guest
157+
--
158+
159+
COPY public.users (id, firstname, lastname, email, phone, password, lastlogin, created_at, modified_at) FROM stdin;
160+
\.
161+
162+
163+
--
164+
-- Name: authors_id_seq; Type: SEQUENCE SET; Schema: public; Owner: guest
165+
--
166+
167+
SELECT pg_catalog.setval('public.authors_id_seq', 1, false);
168+
169+
170+
--
171+
-- Name: books_id_seq; Type: SEQUENCE SET; Schema: public; Owner: guest
172+
--
173+
174+
SELECT pg_catalog.setval('public.books_id_seq', 1, false);
175+
176+
177+
--
178+
-- Name: users_id_seq; Type: SEQUENCE SET; Schema: public; Owner: guest
179+
--
180+
181+
SELECT pg_catalog.setval('public.users_id_seq', 1, false);
182+
183+
184+
--
185+
-- Name: alembic_version alembic_version_pkc; Type: CONSTRAINT; Schema: public; Owner: guest
186+
--
187+
188+
ALTER TABLE ONLY public.alembic_version
189+
ADD CONSTRAINT alembic_version_pkc PRIMARY KEY (version_num);
190+
191+
192+
--
193+
-- Name: authors authors_pkey; Type: CONSTRAINT; Schema: public; Owner: guest
194+
--
195+
196+
ALTER TABLE ONLY public.authors
197+
ADD CONSTRAINT authors_pkey PRIMARY KEY (id);
198+
199+
200+
--
201+
-- Name: books books_pkey; Type: CONSTRAINT; Schema: public; Owner: guest
202+
--
203+
204+
ALTER TABLE ONLY public.books
205+
ADD CONSTRAINT books_pkey PRIMARY KEY (id);
206+
207+
208+
--
209+
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: guest
210+
--
211+
212+
ALTER TABLE ONLY public.users
213+
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
214+
215+
216+
--
217+
-- Name: ix_authors_email; Type: INDEX; Schema: public; Owner: guest
218+
--
219+
220+
CREATE UNIQUE INDEX ix_authors_email ON public.authors USING btree (email);
221+
222+
223+
--
224+
-- Name: ix_authors_phone; Type: INDEX; Schema: public; Owner: guest
225+
--
226+
227+
CREATE UNIQUE INDEX ix_authors_phone ON public.authors USING btree (phone);
228+
229+
230+
--
231+
-- Name: ix_users_email; Type: INDEX; Schema: public; Owner: guest
232+
--
233+
234+
CREATE UNIQUE INDEX ix_users_email ON public.users USING btree (email);
235+
236+
237+
--
238+
-- Name: ix_users_phone; Type: INDEX; Schema: public; Owner: guest
239+
--
240+
241+
CREATE UNIQUE INDEX ix_users_phone ON public.users USING btree (phone);
242+
243+
244+
--
245+
-- Name: books books_author_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: guest
246+
--
247+
248+
ALTER TABLE ONLY public.books
249+
ADD CONSTRAINT books_author_id_fkey FOREIGN KEY (author_id) REFERENCES public.authors(id);
250+
251+
252+
--
253+
-- PostgreSQL database dump complete
254+
--
255+

migrate.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
pipenv run alembic init migrations
3+
if [ $? -eq 0 ]; then
4+
cp env.py migrations
5+
fi
6+
if [ $? -eq 0 ]; then
7+
pipenv run alembic revision --autogenerate -m "Initial migration"
8+
fi
9+
if [ $? -eq 0 ]; then
10+
pipenv run alembic upgrade head
11+
fi

0 commit comments

Comments
 (0)