This directory contains scripts for managing the database and performing maintenance tasks.
Adds the user_id column to the clients table if it doesn't already exist. This is a prerequisite for the update-existing-clients script.
node scripts/add-user-id-column.jsUpdates all existing clients that don't have a user_id with a default value. By default, it uses [email protected] as the user ID, but this can be customized using the DEFAULT_USER_ID environment variable.
# Using default user ID ([email protected])
node scripts/update-existing-clients.js
# Using a custom user ID
[email protected] node scripts/update-existing-clients.jsA wrapper script that runs the update-existing-clients.js script with proper error handling. This is the recommended way to run the update script.
# Using default user ID ([email protected])
node scripts/run-update-clients.js
# Using a custom user ID
[email protected] node scripts/run-update-clients.jsVerifies that all clients have a user_id value and provides statistics about the distribution of user IDs in the database.
node scripts/verify-client-updates.jsA comprehensive script that combines all the necessary steps to ensure clients have user IDs:
- Adds the
user_idcolumn if it doesn't exist - Updates existing clients with the default user ID
- Verifies that all clients have a user_id
# Using default user ID ([email protected])
node scripts/ensure-client-user-ids.js
# Using a custom user ID
[email protected] node scripts/ensure-client-user-ids.jsRuns the TypeScript migration to add the user_id column to the clients table using the TypeScript migration file.
node scripts/run-migration.jsFor convenience, these scripts are also available as npm scripts:
# Run the client update script
npm run db:update-clients
# Run with a custom user ID
[email protected] npm run db:update-clients
# Verify client updates
npm run db:verify-clients
# Run the comprehensive client update process
npm run db:ensure-client-ids
# Run with a custom user ID
[email protected] npm run db:ensure-client-ids