1---2name: naiimtj-nexreel-database3description: Database & Migrations4---56# Database & Migrations78Rules for working with PostgreSQL, SQLAlchemy Core/Text, and Alembic in NexReel.910## Canonical Sources1112- Bootstrap schema: `database/schema.sql`13- Runtime connection code: `fastapi/api/core/database/database.py`14- Shared SQL and serializers: `fastapi/api/core/nexreel/repository.py`15- Migrations: `fastapi/alembic/versions/`1617## Core Conventions1819- Use PostgreSQL-native `UUID` primary keys where the schema already does.20- Use `TIMESTAMPTZ` and `NOW()` for timestamps.21- Use `JSONB` for list-like or structured user preferences.22- Keep bootstrap DDL idempotent with `IF NOT EXISTS` when editing `database/schema.sql`.2324## Tables To Understand First2526- `users` — includes `api_token TEXT UNIQUE` for header-based auth27- `user_followers`28- `media`29- `media_tv`30- `media_tv_seasons`31- `media_tv_episodes`32- `playlists`33- `playlist_followers`34- `forums`35- `forum_followers`36- `messages`37- `plex_data` — summary row: `movie_count`, `tv_count`, `synced_at`38- `plex_movie` — one row per Plex film, `rating_key UNIQUE`; columns include `imdb_id`, `tmdb_id`, `tvdb_id` (nullable TEXT)39- `plex_tv` — one row per Plex show, `rating_key UNIQUE`; columns include `imdb_id`, `tmdb_id`, `tvdb_id` (nullable TEXT)4041## Query Patterns4243- Prefer parameterized `sqlalchemy.text(...)` queries.44- Keep SQL aliases aligned with the serializer functions in `repository.py`.45- Use expanding bind params only when needed for `IN` queries.46- Avoid ad hoc ORM layering that duplicates the repository abstraction already in place.4748## Migrations4950- Use Alembic when the running database must be upgraded incrementally.51- Keep `upgrade()` and `downgrade()` symmetrical.52- Reflect the same schema intent in `database/schema.sql` when the bootstrap path must also change.53- Validate operational impact on Docker init and backup/restore flows.5455## Index Discipline5657Preserve or intentionally update lookup indexes on follower, media, playlist, forum, and message tables when changing access patterns.5859## Testing Implications6061- Schema changes should be validated with the narrowest available backend check.62- If a migration changes payload shape indirectly, coordinate with router and testing updates in the same task.6364## Checklist6566- [ ] Migration has both `upgrade()` and `downgrade()`67- [ ] `down_revision` points to the actual latest migration68- [ ] Bootstrap schema mirrors the intended structure69- [ ] PostgreSQL types stay consistent with runtime queries70- [ ] Raw SQL uses bind parameters, not string interpolation7172---73> Source: [Naiimtj/NexReel](https://github.com/Naiimtj/NexReel) — distributed by [TomeVault](https://tomevault.io).74<!-- tomevault:4.0:skill_md:2026-05-22 -->
Run npx skillmds@latest add tomevault-io/naiimtj-nexreel-database in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Database & Migrations It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.