jiaqing-tee / starquest_jq

0 stars 0 forks source link

Capstone: Authentication DB - Postgres #6

Closed jiaqing-tee closed 3 months ago

jiaqing-tee commented 5 months ago

Create the Postgres DB in a separate container to decouple stuff Reference: https://www.digitalocean.com/community/tutorials/how-to-deploy-postgres-to-kubernetes-cluster#connect-to-postgresql-via-kubectl

jiaqing-tee commented 4 months ago

Connect to PostgreSQL via kubectl

kubectl exec -it postgres-64d86fbbc8-7bd4j -- psql -h localhost -U ps_user --password -p 5432 ps_db
\conninfo

Image

jiaqing-tee commented 4 months ago

Use Postgres

Link: https://www.digitalocean.com/community/tutorials/how-to-use-a-postgresql-database-in-a-flask-application

Create auth database

CREATE USER auth_user WITH PASSWORD 'Input auth_user password';
CREATE DATABASE auth;
GRANT ALL PRIVILEGES ON DATABASE auth TO auth_user;
GRANT ALL ON SCHEMA public TO auth_user;

Check if database is created

\l

Use auth database

\c auth

Create table

CREATE TABLE users (
  id serial primary key,
  email VARCHAR(255) NOT NULL UNIQUE,
  password_hash VARCHAR(162) NOT NULL
);

Grant access to users table

GRANT ALL PRIVILEGES ON TABLE users TO auth_user;

Insert user

INSERT INTO users (email, password_hash) VALUES ('test@domain.com', 'Input_User_Password');