Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"onAutoForward": "ignore"
},
"postCreateCommand": "initdb -D $PGDATA && pg_ctl -D $PGDATA -o '-k /run/postgresql' -l /tmp/pg.log start && createdb chocomax && pg_ctl -D $PGDATA stop",
"postStartCommand": "pg_ctl -D $PGDATA -o '-k /run/postgresql' -l /tmp/pg.log start",
"remoteUser": "vscode"
}
2 changes: 2 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Create Release

permissions:
contents: write
pull-requests: read
statuses: read

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
branches:
- main
paths:
- database/**
- database/**/*.sql
- .github/workflows/unit-tests.yml
pull_request: null
workflow_dispatch:
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ RUN chmod +x /usr/local/bin/*.sh && \
# Drop root privileges
USER postgres

# Copy configuration files
COPY config/. /etc/postgresql/

# Use tini for proper signal handling
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/entrypoint.sh"]

Expand Down
1 change: 0 additions & 1 deletion conf/postgresql.conf

This file was deleted.

17 changes: 17 additions & 0 deletions config/pg_hba.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# PostgreSQL Client Authentication Configuration File
# TYPE DATABASE USER ADDRESS METHOD

# Allow local connections for all users with scram-sha-256
local all all scram-sha-256

# Allow connections from any IP address with scram-sha-256
# host all all 0.0.0.0/0 scram-sha-256
# host all all ::/0 scram-sha-256

# "replication" privilege for streaming replication, by default only from localhost
# local replication all scram-sha-256
# host replication all 127.0.0.1/32 scram-sha-256
# host replication all ::1/128 scram-sha-256

# Allow only Docker bridge network
host all all 172.17.0.0/16 scram-sha-256
1 change: 1 addition & 0 deletions config/postgresql.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
listen_addresses = '*'
2 changes: 1 addition & 1 deletion database/functions/authenticate_user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE OR REPLACE FUNCTION authenticate_user(
p_user_agent TEXT
) RETURNS BOOLEAN AS $$
DECLARE
v_user_id INTEGER;
v_user_id UUID;
BEGIN
-- Attempt to find the user by username and hashed password
SELECT user_id INTO v_user_id
Expand Down
2 changes: 1 addition & 1 deletion database/functions/disable_2fa.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Disable 2FA for a user
CREATE OR REPLACE FUNCTION disable_2fa(p_user_id INTEGER) RETURNS VOID AS $$
CREATE OR REPLACE FUNCTION disable_2fa(p_user_id UUID) RETURNS VOID AS $$
BEGIN
UPDATE user_authentication_methods
SET is_enabled = FALSE, updated_at = NOW()
Expand Down
2 changes: 1 addition & 1 deletion database/functions/get_user_2fa_secret.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Get the user's authentication methods secret
CREATE OR REPLACE FUNCTION get_user_authentication_method_secret(p_user_id INTEGER) RETURNS TABLE (method TEXT, secret TEXT) AS $$
CREATE OR REPLACE FUNCTION get_user_authentication_method_secret(p_user_id UUID) RETURNS TABLE (method TEXT, secret TEXT) AS $$
BEGIN
RETURN QUERY
SELECT authentication_method, user_authentication_method_secret
Expand Down
2 changes: 1 addition & 1 deletion database/functions/is_2fa_enabled.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Check if the user has 2FA enabled
CREATE OR REPLACE FUNCTION is_2fa_enabled(p_user_id INTEGER) RETURNS BOOLEAN AS $$
CREATE OR REPLACE FUNCTION is_2fa_enabled(p_user_id UUID) RETURNS BOOLEAN AS $$
DECLARE
v_enabled BOOLEAN;
BEGIN
Expand Down
2 changes: 1 addition & 1 deletion database/procedures/handle_successful_login.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Update last_login and log successful attempt
CREATE OR REPLACE PROCEDURE handle_successful_login(
p_user_id INTEGER,
p_user_id UUID,
p_ip_address INET,
p_user_agent TEXT
)
Expand Down
2 changes: 1 addition & 1 deletion database/procedures/log_login_attempt.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Log a login attempt (used in both success and failure cases)
CREATE OR REPLACE PROCEDURE log_login_attempt(
p_user_id INTEGER,
p_user_id UUID,
p_ip_address INET,
p_user_agent TEXT,
p_success BOOLEAN
Expand Down
6 changes: 3 additions & 3 deletions database/procedures/register_user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE OR REPLACE PROCEDURE register_user(
p_password_hash VARCHAR,
p_phone_encrypted TEXT,
p_phone_hash TEXT,
p_preferred_language VARCHAR
p_preferred_language_iso_code CHAR(2)
)
LANGUAGE plpgsql AS $$
BEGIN
Expand All @@ -18,7 +18,7 @@ BEGIN
password_hash,
phone_encrypted,
phone_hash,
preferred_language
language_id
)
VALUES (
p_email_encrypted,
Expand All @@ -27,7 +27,7 @@ BEGIN
p_password_hash,
p_phone_encrypted,
p_phone_hash,
p_preferred_language
(SELECT language_id FROM languages WHERE iso_code = p_preferred_language_iso_code)
);
EXCEPTION
WHEN unique_violation THEN
Expand Down
Loading