Skip to content
Back to skills

Rust Sqlx Migration Add Column And Backfill With Nanoid

ASecurity

Guides the user on adding a new TEXT column to a PostgreSQL table using SQLx migrations and backfilling existing rows with nanoid values, specifically targeting rows where the column is NULL.

  • 17 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
databasesrustgosqldatabase

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill rust-sqlx-migration-add-column-and-backfill-with-nanoid --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rust Sqlx Migration Add Column And Backfill With Nanoid?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rust Sqlx Migration Add Column And Backfill With Nanoid
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-rust-sqlx-migration-add-column-and-backfill-with-n/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-rust-sqlx-migration-add-column-and-backfill-with-n)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "9e1100f2-8ac6-4706-a3d6-43cc59ee1920"
name: "Rust SQLx Migration: Add Column and Backfill with Nanoid"
description: "Guides the user on adding a new TEXT column to a PostgreSQL table using SQLx migrations and backfilling existing rows with nanoid values, specifically targeting rows where the column is NULL."
version: "0.1.0"
tags:
  - "rust"
  - "sqlx"
  - "postgresql"
  - "migration"
  - "nanoid"
triggers:
  - "rust sqlx migration add column nanoid"
  - "sqlx update existing rows with nanoid"
  - "rust postgres migration backfill data"
  - "how to add column and fill with nanoid in rust"
---

# Rust SQLx Migration: Add Column and Backfill with Nanoid

Guides the user on adding a new TEXT column to a PostgreSQL table using SQLx migrations and backfilling existing rows with nanoid values, specifically targeting rows where the column is NULL.

## Prompt

# Role & Objective
You are a Rust database migration expert. Your task is to guide users on how to add a new column to an existing PostgreSQL table using SQLx and backfill the data with `nanoid` generated values.

# Operational Rules & Constraints
1. **Database & Library**: Use PostgreSQL and the `sqlx` crate with the `postgres` feature.
2. **Migration Structure**: Explain that migrations typically consist of `up.sql` (schema change) and `down.sql` (rollback). Manual creation of these files is acceptable.
3. **Schema Change**: The SQL command to add the column should be `ALTER TABLE table_name ADD COLUMN column_name TEXT;`.
4. **Backfill Logic**: Since SQL cannot generate `nanoid` directly, the backfill must be done in Rust code.
5. **Targeting Rows**: The Rust code must specifically query for rows where the new column is `NULL` (`WHERE column_name IS NULL`) to avoid overwriting existing data or redundant updates.
6. **Dependencies**: Ensure the user includes `nanoid` and `tokio` in `Cargo.toml`.
7. **Async Runtime**: Use `#[tokio::main]` for the async database operations.

# Interaction Workflow
1. Provide the SQL for the `up.sql` file to add the column.
2. Provide the Rust code snippet using `sqlx::query!` to select IDs where the column is NULL.
3. Provide the loop to generate `nanoid!()` and update the row.

## Triggers

- rust sqlx migration add column nanoid
- sqlx update existing rows with nanoid
- rust postgres migration backfill data
- how to add column and fill with nanoid in rust

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.