Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:23:07 +08:00
commit 8b69ed05af
12 changed files with 812 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
# Assets
Bundled resources for database-test-manager skill
- [ ] test_data_schema_template.json: Template for defining test data schemas.
- [ ] database_schema_definition.json: Example database schema definition for validation.
- [ ] example_migration_script.sql: Example SQL migration script for testing.
- [ ] docker-compose.yml: Docker Compose file for setting up test databases.

View File

@@ -0,0 +1,142 @@
{
"_comment": "Example database schema definition for validation. This can be used as a template.",
"schema_name": "public",
"tables": [
{
"table_name": "users",
"_comment": "Table for storing user information",
"columns": [
{
"column_name": "id",
"data_type": "SERIAL",
"is_nullable": false,
"is_primary_key": true,
"is_unique": true,
"_comment": "Unique identifier for the user"
},
{
"column_name": "username",
"data_type": "VARCHAR(50)",
"is_nullable": false,
"is_unique": true,
"_comment": "Unique username for login"
},
{
"column_name": "email",
"data_type": "VARCHAR(255)",
"is_nullable": false,
"is_unique": true,
"_comment": "Email address of the user"
},
{
"column_name": "password_hash",
"data_type": "VARCHAR(255)",
"is_nullable": false,
"_comment": "Hashed password for security"
},
{
"column_name": "created_at",
"data_type": "TIMESTAMP",
"is_nullable": false,
"default_value": "NOW()",
"_comment": "Timestamp of user creation"
}
],
"constraints": [
{
"constraint_name": "unique_username",
"constraint_type": "UNIQUE",
"columns": ["username"],
"_comment": "Ensures usernames are unique"
},
{
"constraint_name": "unique_email",
"constraint_type": "UNIQUE",
"columns": ["email"],
"_comment": "Ensures email addresses are unique"
}
]
},
{
"table_name": "products",
"_comment": "Table for storing product information",
"columns": [
{
"column_name": "id",
"data_type": "SERIAL",
"is_nullable": false,
"is_primary_key": true,
"is_unique": true,
"_comment": "Unique identifier for the product"
},
{
"column_name": "name",
"data_type": "VARCHAR(100)",
"is_nullable": false,
"_comment": "Name of the product"
},
{
"column_name": "description",
"data_type": "TEXT",
"is_nullable": true,
"_comment": "Detailed description of the product"
},
{
"column_name": "price",
"data_type": "NUMERIC(10, 2)",
"is_nullable": false,
"_comment": "Price of the product"
},
{
"column_name": "created_at",
"data_type": "TIMESTAMP",
"is_nullable": false,
"default_value": "NOW()",
"_comment": "Timestamp of product creation"
}
]
},
{
"table_name": "orders",
"_comment": "Table for storing order information",
"columns": [
{
"column_name": "id",
"data_type": "SERIAL",
"is_nullable": false,
"is_primary_key": true,
"is_unique": true,
"_comment": "Unique identifier for the order"
},
{
"column_name": "user_id",
"data_type": "INTEGER",
"is_nullable": false,
"_comment": "Foreign key referencing the users table"
},
{
"column_name": "order_date",
"data_type": "TIMESTAMP",
"is_nullable": false,
"default_value": "NOW()",
"_comment": "Date and time the order was placed"
},
{
"column_name": "total_amount",
"data_type": "NUMERIC(10, 2)",
"is_nullable": false,
"_comment": "Total amount of the order"
}
],
"foreign_keys": [
{
"constraint_name": "fk_user_id",
"columns": ["user_id"],
"referenced_table": "users",
"referenced_columns": ["id"],
"_comment": "Foreign key relationship to the users table"
}
]
}
]
}

View File

@@ -0,0 +1,75 @@
version: "3.9"
services:
# PostgreSQL Database Service
postgres:
image: postgres:14 # Use PostgreSQL version 14
container_name: test-db-postgres
environment:
POSTGRES_USER: test_user # Database username
POSTGRES_PASSWORD: test_password # Database password
POSTGRES_DB: test_database # Default database name
ports:
- "5432:5432" # Expose port 5432 for external access
volumes:
- postgres_data:/var/lib/postgresql/data # Persist data in a volume
healthcheck:
test: ["CMD-SHELL", "pg_isready -U test_user -d test_database"] # Check if the database is ready
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped # Restart policy
# MySQL Database Service
mysql:
image: mysql:8.0 # Use MySQL version 8.0
container_name: test-db-mysql
environment:
MYSQL_ROOT_PASSWORD: root_password # Root password for MySQL
MYSQL_USER: test_user # Database username
MYSQL_PASSWORD: test_password # Database password
MYSQL_DATABASE: test_database # Default database name
ports:
- "3306:3306" # Expose port 3306 for external access
volumes:
- mysql_data:/var/lib/mysql # Persist data in a volume
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost -u root -proot_password"] # Check if the database is ready
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped # Restart policy
# MongoDB Database Service
mongo:
image: mongo:latest # Use the latest MongoDB image
container_name: test-db-mongo
environment:
MONGO_INITDB_ROOT_USERNAME: root # Root username
MONGO_INITDB_ROOT_PASSWORD: root_password # Root password
ports:
- "27017:27017" # Expose port 27017 for external access
volumes:
- mongo_data:/data/db # Persist data in a volume
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.runCommand('ping').ok"] # Check if the database is ready
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped # Restart policy
# Redis Service (Example for caching or other use cases)
redis:
image: redis:latest # Use the latest Redis image
container_name: test-redis
ports:
- "6379:6379" # Expose port 6379 for external access
volumes:
- redis_data:/data # Persist data in a volume
restart: unless-stopped # Restart policy
volumes:
postgres_data: # Volume for PostgreSQL data
mysql_data: # Volume for MySQL data
mongo_data: # Volume for MongoDB data
redis_data: # Volume for Redis data

View File

@@ -0,0 +1,39 @@
-- Example SQL migration script for database-test-manager plugin tests.
-- This script demonstrates basic table creation and data insertion.
-- Table creation: Replace 'your_table_name' with your actual table name.
CREATE TABLE IF NOT EXISTS your_table_name (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Data insertion: Replace with your initial data. Use Faker for more realistic data during testing.
INSERT INTO your_table_name (name, email) VALUES
('John Doe', 'john.doe@example.com'),
('Jane Smith', 'jane.smith@example.com');
-- Add an index (optional): Useful for optimizing queries.
CREATE INDEX idx_name ON your_table_name (name);
-- Add a constraint (optional): Enforces data integrity. Example: email must be in valid format
-- ALTER TABLE your_table_name ADD CONSTRAINT chk_email CHECK (email LIKE '%@%.%');
-- INSERT additional test data (example for parameterized testing):
-- INSERT INTO your_table_name (name, email) VALUES ('${test_name}', '${test_email}'); -- Placeholder for test parameters
-- Add a new column (example migration):
-- ALTER TABLE your_table_name ADD COLUMN phone_number VARCHAR(20);
-- Drop a column (example migration):
-- ALTER TABLE your_table_name DROP COLUMN phone_number;
-- Rename a column (example migration):
-- ALTER TABLE your_table_name RENAME COLUMN old_column_name TO new_column_name;
-- Modify a column (example migration):
-- ALTER TABLE your_table_name MODIFY COLUMN name VARCHAR(100);
-- Example of a more complex query (useful for testing query performance):
-- SELECT * FROM your_table_name WHERE name LIKE '%John%' ORDER BY created_at DESC LIMIT 10;

View File

@@ -0,0 +1,104 @@
{
"_comment": "Template for defining test data schemas. Use this as a starting point for creating your test data definitions.",
"schema_name": "your_schema_name",
"_comment": "The name of the database schema this data applies to. Often 'public'.",
"tables": [
{
"table_name": "users",
"_comment": "The name of the table.",
"columns": [
{
"column_name": "id",
"data_type": "INTEGER",
"primary_key": true,
"auto_increment": true,
"_comment": "Example of an integer primary key with auto-increment."
},
{
"column_name": "username",
"data_type": "VARCHAR(255)",
"nullable": false,
"unique": true,
"faker": "user_name",
"_comment": "Example using Faker to generate usernames."
},
{
"column_name": "email",
"data_type": "VARCHAR(255)",
"nullable": false,
"unique": true,
"faker": "email",
"_comment": "Example using Faker to generate email addresses."
},
{
"column_name": "created_at",
"data_type": "TIMESTAMP",
"default": "CURRENT_TIMESTAMP",
"_comment": "Example of a timestamp column with a default value."
}
],
"rows": [
{
"username": "existing_user",
"email": "existing@example.com",
"_comment": "Optionally specify exact values for specific rows. Faker will be used if not specified"
}
]
},
{
"table_name": "products",
"_comment": "Example of another table.",
"columns": [
{
"column_name": "id",
"data_type": "INTEGER",
"primary_key": true,
"auto_increment": true
},
{
"column_name": "name",
"data_type": "VARCHAR(255)",
"nullable": false,
"faker": "product_name",
"_comment": "Using a custom Faker provider. Requires the provider to be installed."
},
{
"column_name": "price",
"data_type": "DECIMAL(10, 2)",
"nullable": false,
"faker": "pyfloat:left_digits=3,right_digits=2,positive=True",
"_comment": "Example of using pyfloat for generating prices. Can use faker.pyfloat arguments."
},
{
"column_name": "description",
"data_type": "TEXT",
"faker": "paragraph",
"_comment": "Example of using faker to generate a paragraph of text."
},
{
"column_name": "user_id",
"data_type": "INTEGER",
"nullable": false,
"foreign_key": "users.id",
"_comment": "Example of a foreign key relationship. Requires the 'users' table to exist and have an 'id' column."
}
],
"rows": [
{
"name": "Specific Product",
"price": 99.99,
"description": "A very specific product description.",
"user_id": 1
}
]
}
],
"options": {
"number_of_rows_per_table": 5,
"_comment": "Default number of rows to create for each table if no 'rows' key is specified. Defaults to 1 if not specified.",
"rollback_transaction": true,
"_comment": "Whether to rollback the transaction after the data is inserted. Defaults to true.",
"truncate_tables": false,
"_comment": "Whether to truncate the tables before inserting data. Defaults to false."
}
}