feat: seed data and fix db config
This commit is contained in:
parent
83545fb854
commit
b637762744
@ -1,13 +1,27 @@
|
||||
-- I DO NOT KNOW IF THIS WORKS --
|
||||
-- I AM PLAYING ARROUND WITH START UP SCRIPTS FOR THE CONTAINER --
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
-- Drop existing roles/users if they exist
|
||||
DROP ROLE IF EXISTS admin;
|
||||
DROP USER IF EXISTS admin;
|
||||
DROP TABLE dev_users
|
||||
|
||||
-- Create admin user with strong password using bcrypt
|
||||
CREATE USER admin WITH PASSWORD 'password';
|
||||
CREATE TABLE IF NOT EXISTS dev_users (
|
||||
id UUID PRIMARY KEY DEFAULT (uuid_generate_v4()),
|
||||
first_name character varying(255) NOT NULL,
|
||||
last_name character varying(255) NOT NULL,
|
||||
email character varying(255) UNIQUE NOT NULL,
|
||||
phone_number character varying(255),
|
||||
created_at timestamp with time zone DEFAULT now(),
|
||||
updated_at timestamp with time zone DEFAULT now()
|
||||
);
|
||||
|
||||
-- Grant all privileges
|
||||
ALTER ROLE admin SUPERUSER;
|
||||
GRANT ALL PRIVILEGES TO admin;
|
||||
-- Seed Data
|
||||
INSERT INTO dev_users (first_name, last_name, email, phone_number, created_at, updated_at)
|
||||
VALUES
|
||||
('John', 'Doe', 'john.doe@example.com', '(555) 123-4567', now(), now()),
|
||||
('Jane', 'Smith', 'jane.smith@example.com', '(555) 123-4568', now(), now()),
|
||||
('Bob', 'Johnson', 'bob.johnson@example.com', '(555) 123-4569', now(), now()),
|
||||
('Alice', 'Brown', 'alice.brown@example.com', '(555) 123-4570', now(), now()),
|
||||
('Charlie', 'Wilson', 'charlie.wilson@example.com', '(555) 123-4571', now(), now()),
|
||||
('Eva', 'Davis', 'eva.davis@example.com', '(555) 123-4572', now(), now()),
|
||||
('Frank', 'Miller', 'frank.miller@example.com', '(555) 123-4573', now(), now()),
|
||||
('Grace', 'Taylor', 'grace.taylor@example.com', '(555) 123-4574', now(), now()),
|
||||
('Henry', 'Anderson', 'henry.anderson@example.com', '(555) 123-4575', now(), now()),
|
||||
('Isabella', 'King', 'isabella.king@example.com', '(555) 123-4576', now(), now());
|
||||
|
3
.env
3
.env
@ -1,9 +1,10 @@
|
||||
DB_USER=admin
|
||||
DB_PASSWORD=password
|
||||
DB_ROOT_PASSWORD=rootpassword
|
||||
DB_NAME=worklog
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
DB_EXPOSED_PORT=6767
|
||||
DB_EXPOSED_PORT=5432
|
||||
DB_TZ=America/Chicago
|
||||
|
||||
VOLUME_ROOT="./.container_volume"
|
||||
|
@ -5,9 +5,9 @@ services:
|
||||
ports:
|
||||
- "${DB_EXPOSED_PORT}:${DB_PORT}"
|
||||
environment:
|
||||
POSTGRES_DB: worklog
|
||||
POSTGRES_USER: admin
|
||||
POSTGRES_PASSWORD: password
|
||||
- POSTGRES_DB=worklog
|
||||
- POSTGRES_USER=${DB_USER}
|
||||
- POSTGRES_PASSWORD=${DB_PASSWORD}
|
||||
volumes:
|
||||
- "${VOLUME_ROOT}/db:/var/lib/postgresql/data"
|
||||
- "${VOLUME_ROOT}/scripts:/docker-entrypoint-initdb.d/"
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
gorm.Model
|
||||
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
|
||||
FirstName string `gorm:"size:255"`
|
||||
LastName string `gorm:"size:255"`
|
||||
|
@ -55,11 +55,11 @@ func (r *UserRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
return r.db.WithContext(ctx).Delete(&user).Error
|
||||
}
|
||||
|
||||
func (r *UserRepository) List(ctx context.Context, offset int, limit int) ([]entities.User, int64, error) {
|
||||
var users []entities.User
|
||||
func (r *UserRepository) List(ctx context.Context, offset int, limit int) ([]entities.DevUser, int64, error) {
|
||||
var users []entities.DevUser // TODO: make sure to make this abstractable
|
||||
var totalUserCount int64
|
||||
|
||||
if err := r.db.WithContext(ctx).Where("1 = 1").Count(&totalUserCount).Offset(offset).Limit(limit); err != nil {
|
||||
if err := r.db.WithContext(ctx).Find(&users).Count(&totalUserCount).Offset(offset).Limit(limit); err != nil {
|
||||
return nil, 0, err.Error
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user