Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@puya/pdcsc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
PDCSC - Changeset Processor
PDCSC is a Node.js script that processes database changes, generates SQL scripts based on uncommitted changes in the codebase, and allows automatic backup and execution of scripts against databases. It supports multiple options for different environments, such as running in a Git pipeline or directly on a development machine.
Features
- Generate Changeset Scripts: Automatically generates SQL scripts based on the changes detected in the codebase.
- Backup and Restore Database: Automatically creates a backup of the database before applying the changes.
- Multiple Modes of Execution:
-rop: Can be used in Git pipelines to run scripts before merging a branch to ensure the database is updated before the merge.-rom: Executes the changes directly on the main database after running the backup.- Default mode: Runs the changes on the local machine without directly affecting the main database.
Installation
You can install PDCSC globally for CLI use or locally in your project.
Global Installation
Install globally to use the pdcsc command:
npm install -g pdcscLocal Installation
Install locally in your project:
npm install pdcscUsage
CLI
Once installed globally, you can use the pdcsc command in your terminal.
pdcsc [options]Options
-rop: Run the script in a Git pipeline environment to test changes before merging.-rom: Run the script directly on the main database after applying changes to the backup.-csf [file]: Specify a custom changeset file. If not provided, the script will generate one.-s [server]: Specify the database server.-u [user]: Specify the database user.-p [password]: Specify the database password.-d [database]: Specify the database name.
Examples
Run the script on the local machine:
pdcsc
Run the script with the
-romoption to apply changes directly on the main database after the backup:pdcsc -romRun the script with the
-ropoption in a Git pipeline:pdcsc -ropGenerate a custom changeset file:
pdcsc -csf myChangeset.txtSpecify a custom database server, user, and password:
pdcsc -s "myServer" -u "myUser" -p "myPassword" -d "myDatabase"
Configuration
The configuration for the script is stored in the config.json file, which should be placed in the root directory of the project. Here's an example of how the configuration file should look:
{
"database": {
"server": "localhost",
"user": "db_user",
"password": "db_password",
"databaseName": "my_database"
},
"paths": {
"basePath": "./",
"backupDir": "./backups",
"changesetFolderName": "Changes",
"appVersionFormat": "YYYY-MM-DD_HH-mm-ss",
"timestampLocale": "fa",
"masterBranchName": "origin/dev"
}
}- database: Database credentials such as the server, username, password, and database name.
- paths: Paths used for backups, changesets, and other files in the script.
Workflow Example
Scenario 1: Running in a GitLab Pipeline
In a GitLab CI/CD pipeline, you can use the -rop option to ensure that the database is updated before merging a branch. The pipeline configuration might look like this:
stages:
- build
- deploy
deploy:
stage: deploy
script:
- pdcsc -rop
only:
- merge_requestsScenario 2: Running Locally on Development Machine
If you're working locally, you can simply run the script without any options to generate the changeset and apply it to the backup database.
pdcscYou can also provide specific database details via the command line:
pdcsc -s "dev-server" -u "dev-user" -p "dev-password" -d "dev-db"Scenario 3: Deploying Changes to the Main Database
To deploy the changes directly to the main database after the backup:
pdcsc -romLicense
This project is licensed under the MIT License - see the LICENSE file for details.