Database sqlx
Database operations — create migrations, modify schema, check migration status, and manage PostgreSQL tables (sqlx). Use when adding/changing tables, fields, indexes, constraints, or working with migrations.From its SKILL.md
npx -y skills add milkyskies/milky-kit --skill database-sqlxAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.7 KB, as published. Nobody here has run it
Database: $ARGUMENTS
Perform database schema and migration operations for $ARGUMENTS.
How the database works
- PostgreSQL connected via
DATABASE_URL - sqlx — compile-time checked SQL queries via
sqlx::query!()macros - Migrations are
.sqlfiles with timestamp-based names - Offline metadata in
.sqlx/allows building without a database
Creating a new migration
Step 1 — Create the .sql file
Check the last timestamp and create the next file:
ls packages/infrastructure/pg_migrations/
Create e.g. 20260302000000_add_notifications.sql:
CREATE TABLE IF NOT EXISTS notification (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
message TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_notification_user ON notification (user_id);
Step 2 — Apply and regenerate offline metadata
# Restart app to apply migration, then:
cargo sqlx prepare --workspace
Step 3 — Add the repository
- Domain model in
packages/domain/src/models/ - Repository trait in
packages/domain/src/repositories/ - Implementation in
packages/infrastructure/src/db/pg_repositories/usingsqlx::query!()macros
Step 4 — Verify
cargo check -p infrastructure
SQLX_OFFLINE=true cargo check --workspace
Modifying an existing table
Never edit an existing migration file. Create a new ALTER TABLE migration.
Schema conventions
- Always use
IF NOT EXISTS(idempotency) - Always add
created_atandupdated_atwithDEFAULT now() - Use
CHECKconstraints for enum-like fields - Use
TEXTfor strings,JSONBfor structured data - Timestamp-based filenames to avoid collisions
sqlx query rules
- Use
&valfor String parameters,.as_deref()forOption<String> - Only SELECT columns you actually use
- Never delete
.sqlx/directory - After any query or schema change:
cargo sqlx prepare --workspace
Checklist
- Migration
.sqlfile created withIF NOT EXISTS - Timestamp-based filename
- Migration applied
- Offline metadata regenerated:
cargo sqlx prepare --workspace - Repository trait + implementation added
-
cargo check -p infrastructurepasses -
SQLX_OFFLINE=true cargo check --workspacepasses