Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Use the official PostgreSQL image
FROM postgres:latest

# Set environment variables (without password authentication)
ENV POSTGRES_USER=dbuser
ENV POSTGRES_DB=demo
ENV POSTGRES_HOST_AUTH_METHOD=trust

# Copy initialization SQL script
COPY init.sql /docker-entrypoint-initdb.d/

# Expose PostgreSQL port
EXPOSE 5432
71 changes: 71 additions & 0 deletions db/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# PostgreSQL Database for Test Genie

This project is a dockerized PostgreSQL database that provides the backend storage for Test Genie, a test automation management system. The database contains tables for managing test suites, test cases, and test steps.

## Project Structure

```sh
db
├── Dockerfile # Docker definition of the PostgreSQL DB
├── init.sql # SQL scripts to create tables and set up database schema
└── README.md # Project documentation

```

## Database Schema

The database contains the following tables:

1. **test_suites**: Stores test suite information

- id, name, description, timestamps (created_at, updated_at, deleted_at)

2. **test_cases**: Stores individual test cases

- id, test_suite_id, description, timestamps

3. **test_steps**: Stores test execution steps
- id, test_case_id, command, selector, value, length_value, contained_text, chain_option, is_chained, step_order, timestamps

## Setup Instructions

1. **Build the Docker image:**

```sh
docker build -t test-genie-db .

```

2. **Run the container:**

```sh
docker run -d --name test-genie-postgres -p 5432:5432 test-genie-db

```

## Usage

Once the container is running, you can connect to the database using:

```sh
psql -h localhost -U dbuser -d demo

```

The database is configured with the following credentials:

- Username: dbuser
- Database: demo
- Port: 5432
- Authentication: trust (no password required)

## Features

- Automatic timestamp management for created_at and updated_at fields
- Soft delete support via deleted_at fields
- Optimized indexes for better query performance
- Automatic trigger-based updated_at timestamp updates

## License

This project is licensed under the MIT License.
68 changes: 68 additions & 0 deletions db/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
-- Create test_suites table
CREATE TABLE test_suites (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE
);

-- Create test_cases table
CREATE TABLE test_cases (
id SERIAL PRIMARY KEY,
test_suite_id INTEGER NOT NULL REFERENCES test_suites(id),
description TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE
);

-- Create test_steps table
CREATE TABLE test_steps (
id SERIAL PRIMARY KEY,
test_case_id INTEGER NOT NULL REFERENCES test_cases(id),
command VARCHAR(255) NOT NULL,
selector TEXT,
value TEXT,
length_value INTEGER,
contained_text TEXT,
chain_option VARCHAR(50),
is_chained BOOLEAN DEFAULT false,
step_order INTEGER NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE
);

-- Create indexes for better query performance
CREATE INDEX idx_test_cases_suite_id ON test_cases(test_suite_id);
CREATE INDEX idx_test_steps_case_id ON test_steps(test_case_id);
CREATE INDEX idx_test_suites_deleted_at ON test_suites(deleted_at);
CREATE INDEX idx_test_cases_deleted_at ON test_cases(deleted_at);
CREATE INDEX idx_test_steps_deleted_at ON test_steps(deleted_at);

-- Create function to update updated_at timestamp
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ language 'plpgsql';

-- Create triggers to automatically update updated_at
CREATE TRIGGER update_test_suites_updated_at
BEFORE UPDATE ON test_suites
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();

CREATE TRIGGER update_test_cases_updated_at
BEFORE UPDATE ON test_cases
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();

CREATE TRIGGER update_test_steps_updated_at
BEFORE UPDATE ON test_steps
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();