### Complete Migrondi Workflow Example in F# Source: https://context7.com/angelmunoz/migrondi/llms.txt A full example demonstrating the typical migration workflow, including configuration, initialization, status checks, previewing, applying migrations, and creating new ones. ```fsharp open Migrondi.Core open Microsoft.Extensions.Logging // 1. Configure the service let config = { MigrondiConfig.Default with connection = "Host=localhost;Database=myapp;Username=user;Password=pass" migrations = "./migrations" driver = MigrondiDriver.Postgresql tableName = "__migrations" } // 2. Create logger and service let logger = LoggerFactory.Create(fun builder -> builder.AddConsole() |> ignore ).CreateLogger() let migrondi = Migrondi.MigrondiFactory(config, ".", ?logger = Some logger) // 3. Initialize database migrondi.Initialize() // 4. Check current status let migrations = migrondi.MigrationsList() printfn "Total migrations: %d" migrations.Count let pendingCount = migrations |> Seq.filter (function Pending _ -> true | _ -> false) |> Seq.length let appliedCount = migrations |> Seq.filter (function Applied _ -> true | _ -> false) |> Seq.length printfn "Applied: %d, Pending: %d" appliedCount pendingCount // 5. Preview what would be applied let pending = migrondi.DryRunUp() for m in pending do printfn "Would apply: %s" m.name // 6. Apply all pending migrations try let applied = migrondi.RunUp() printfn "Successfully applied %d migrations" applied.Count with | :? MigrationApplicationFailed as ex -> printfn "Migration failed: %s" ex.Migration.name // 7. Create a new migration let newMigration = migrondi.RunNew( "add-email-index", upContent = "CREATE INDEX idx_users_email ON users(email);", downContent = "DROP INDEX idx_users_email;" ) printfn "Created: %s" newMigration.name ``` -------------------------------- ### Install Migrondi as a .NET Tool Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/index.md Use this command to install Migrondi globally as a .NET tool. Ensure you have the .NET SDK installed. ```bash dotnet tool install Migrondi ``` -------------------------------- ### Migrondi CLI Configuration Example Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/configuration.md This example shows how to configure Migrondi using CLI options. Configuration flags must precede the command (e.g., 'up --dry'). ```bash migrondi --driver sqlite --connection "Data Source=./migrondi.db" up --dry ``` -------------------------------- ### Install Migrondi on Linux/OSX via Script Source: https://github.com/angelmunoz/migrondi/blob/vnext/README.md This command downloads and executes an installation script for Linux and macOS. It installs Migrondi to a default location and attempts to add it to your PATH. ```bash curl -fsSL https://raw.githubusercontent.com/AngelMunoz/Migrondi/vnext/migrondi_install.sh | bash ``` -------------------------------- ### Implement Custom Migration Source Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Provide a custom IMiMigrationSource implementation for non-local storage. This example shows a basic structure for reading and writing content, and listing files. ```fsharp open Migrondi.Core.FileSystem let customSource = { new IMiMigrationSource with member _.ReadContent(uri) = "..." member _.ReadContentAsync(uri, ct) = task { return "..." } member _.WriteContent(uri, content) = () member _.WriteContentAsync(uri, content, ct) = task { () } member _.ListFiles(locationUri) = Seq.empty member _.ListFilesAsync(locationUri, ct) = task { return Seq.empty } } let migrondi = Migrondi.MigrondiFactory( config, ".", ?logger = Some logger, source = customSource ) ``` -------------------------------- ### Implement Custom Migration Source in F# Source: https://context7.com/angelmunoz/migrondi/llms.txt Implement the IMiMigrationSource interface to store migrations in cloud storage or other backends. This example shows how to create a custom source for S3, HTTP, or other storage. ```fsharp open System open System.Threading open System.Threading.Tasks open Migrondi.Core open Migrondi.Core.FileSystem // Create custom source for S3, HTTP, or other storage let createCustomSource() = { new IMiMigrationSource with member _.ReadContent(uri: Uri) = // Implement sync read from your storage "-- SQL content from remote storage" member _.ReadContentAsync(uri: Uri, ?cancellationToken: CancellationToken) = task { // Implement async read from your storage return "-- SQL content from remote storage" } member _.WriteContent(uri: Uri, content: string) = // Implement sync write to your storage () member _.WriteContentAsync(uri: Uri, content: string, ?cancellationToken: CancellationToken) = task { // Implement async write to your storage () } member _.ListFiles(locationUri: Uri) = // Return sequence of migration URIs at location seq { yield Uri(locationUri, "1695829818636_CreateUsersTable.sql") yield Uri(locationUri, "1695829860594_CreateProfilesTable.sql") } member _.ListFilesAsync(locationUri: Uri, ?cancellationToken: CancellationToken) = task { return seq { yield Uri(locationUri, "1695829818636_CreateUsersTable.sql") } } } // Use custom source with MigrondiFactory let customSource = createCustomSource() let migrondi = Migrondi.MigrondiFactory( config, rootDirectory = ".", migrationSource = customSource ) ``` -------------------------------- ### Install Migrondi on Windows via PowerShell Script Source: https://github.com/angelmunoz/migrondi/blob/vnext/README.md This command downloads and executes an installation script for Windows using PowerShell. It installs Migrondi to a default location and attempts to add it to your user PATH. ```powershell iwr https://raw.githubusercontent.com/AngelMunoz/Migrondi/vnext/migrondi_install.ps1 -UseBasicParsing | iex ``` -------------------------------- ### Generated Migration File Structure Source: https://context7.com/angelmunoz/migrondi/llms.txt Example structure of a generated SQL migration file, including metadata and UP/DOWN SQL statements. ```sql -- MIGRONDI:NAME=1695873658869_create-users-table.sql -- MIGRONDI:TIMESTAMP=1695873658869 -- ---------- MIGRONDI:UP ---------- create table users ( id integer primary key, name text not null, email text not null, password text not null, created_at datetime not null, updated_at datetime not null ); -- ---------- MIGRONDI:DOWN ---------- drop table users; ``` -------------------------------- ### Define MSTest Unit Tests Source: https://github.com/angelmunoz/migrondi/blob/vnext/AGENTS.md Template for creating MSTest classes in F# with setup, cleanup, and parameterized test methods. ```fsharp [] type MyTests() = [] member _.Setup() = // setup code [] member _.Cleanup() = // cleanup code [] [] member _.``Test description``(input, expected) = Assert.AreEqual(expected, input) ``` -------------------------------- ### Migrondi CLI Usage Reference Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/index.md This provides a quick reference for Migrondi commands and options. Use 'init' to create a configuration file, 'create' to generate new migration scripts, 'apply' to run migrations, 'down' to rollback, and 'list' or 'show-state' to check migration status. ```bash Description: A dead simple SQL migrations runner, apply or rollback migrations at your ease Usage: Migrondi [command] [options] Options: --version Show version information -?, -h, --help Show help and usage information Commands: init, setup Creates a migrondi.json file where the comand is invoked or the path provided [] create, new This will create a new SQL migration file in the configured directory for migrations apply, up Runs migrations against the configured database [] down, rollback Runs migrations against the configured database [] list, show Reads migrations files and the database to show what is the current state of the migrations show-state, status Checks whether the migration file has been applied or not to the database ``` -------------------------------- ### Execute complete migration workflow Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Demonstrates the full lifecycle from configuration and service initialization to applying migrations. ```fsharp open Migrondi.Core open Microsoft.Extensions.Logging // 1. Create configuration let config = { MigrondiConfig.Default with connection = "Data Source=./myapp.db" migrations = "./migrations" } // 2. Create logger let logger = LoggerFactory.Create(fun builder -> builder.AddConsole() |> ignore) .CreateLogger() // 3. Create service let migrondi = Migrondi.MigrondiFactory(config, ".", ?logger = Some logger) // 4. Initialize database migrondi.Initialize() // 5. List current status let migrations = migrondi.MigrationsList() printfn "Current migrations: %d" migrations.Count // 6. Dry run to see what would apply let pending = migrondi.DryRunUp() printfn "Pending migrations: %d" pending.Count // 7. Apply migrations let applied = migrondi.RunUp() printfn "Applied %d migrations" applied.Count ``` -------------------------------- ### Initialize Migrondi Project Source: https://context7.com/angelmunoz/migrondi/llms.txt Initializes a new Migrondi project by creating a `migrondi.json` configuration file and a migrations directory. ```bash # Initialize in current directory migrondi init # Initialize in specific path migrondi init /path/to/project ``` -------------------------------- ### Build Migrondi Projects Source: https://github.com/angelmunoz/migrondi/blob/vnext/AGENTS.md Commands to build the project using FsMake or the standard dotnet CLI. ```bash # Full build with FsMake dotnet fsi build.fsx # Direct dotnet build dotnet build src/Migrondi/Migrondi.fsproj dotnet build src/Migrondi.Core/Migrondi.Core.fsproj # Build for specific runtime dotnet fsi build.fsx build:runtime -- linux-x64 ``` -------------------------------- ### Create Migrondi Service in F# Source: https://context7.com/angelmunoz/migrondi/llms.txt Instantiate the `IMigrondi` service using `MigrondiFactory`. Configuration includes connection string, migration directory, and driver. An optional logger can be provided. ```fsharp open Migrondi.Core open Microsoft.Extensions.Logging // Create configuration let config = { MigrondiConfig.Default with connection = "Data Source=./myapp.db" migrations = "./migrations" driver = MigrondiDriver.Sqlite } // Create logger (optional) let logger = LoggerFactory.Create(fun builder -> builder.AddConsole() |> ignore) .CreateLogger() // Create service with default local file system source let migrondi = Migrondi.MigrondiFactory(config, ".", ?logger = Some logger) // Initialize database (creates migrations tracking table) migrondi.Initialize() ``` -------------------------------- ### Initialize Migrondi Factory in F# Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/library.md Initialize the Migrondi factory with default configuration and a specified migrations directory. ```fsharp open Migrondi.Core let config = MigrondiConfig.Default let migrondi = Migrondi.MigrondiFactory(config, ".") ``` -------------------------------- ### Configure Migrondi PATH for Linux/OSX Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/index.md Add these lines to your ~/.bashrc or ~/.zshrc file to make the Migrondi command available globally. Replace '$HOME/Apps/migrondi' with the actual directory where you downloaded the Migrondi binary. ```bash # you can put this at the end of your ~/.bashrc or ~/.zshrc # $HOME/Apps/migrondi is a directory where you have downloaded your "Migrondi" binary export MIGRONDI_HOME="$HOME/Apps/migrondi" export PATH="$PATH:$MIGRONDI_HOME" ``` -------------------------------- ### Restore Dependencies and Initialize Migrondi Source: https://github.com/angelmunoz/migrondi/blob/vnext/CONTRIBUTING.md Clone the forked repository, restore project dependencies, and initialize Migrondi to create local configuration files. ```sh git clone dotnet restore dotnet run --project src/Migrondi -- init ``` -------------------------------- ### Run CLI Application Source: https://github.com/angelmunoz/migrondi/blob/vnext/AGENTS.md Command to execute the Migrondi CLI. ```bash dotnet run --project src/Migrondi -- ``` -------------------------------- ### Add Migrondi Package Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/library.md Use the .NET CLI to add the Migrondi.Core package to your project. ```bash dotnet add package Migrondi.Core ``` -------------------------------- ### Preview Migrations with Dry Run Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Preview which migrations would be applied without actually executing them. This is useful for verifying migration plans. ```fsharp let pending = migrondi.DryRunUp() for migration in pending do printfn "Would apply: %s" migration.name printfn "SQL: %s" migration.upContent ``` -------------------------------- ### Migrondi Configuration via CLI Options Source: https://context7.com/angelmunoz/migrondi/llms.txt Configures Migrondi settings like driver and connection string directly via command-line arguments before executing a command. ```bash # CLI options (must be passed before the command) migrondi --driver sqlite --connection "Data Source=./migrondi.db" up --dry ``` -------------------------------- ### Migrondi Configuration via Environment Variables Source: https://context7.com/angelmunoz/migrondi/llms.txt Sets Migrondi configuration options using environment variables for connection string, migrations path, table name, and driver. ```bash # Environment variables export MIGRONDI_CONNECTION_STRING="Data Source=./myapp.db" export MIGRONDI_MIGRATIONS="./migrations" export MIGRONDI_TABLE_NAME="__migrondi_migrations" export MIGRONDI_DRIVER="sqlite" ``` -------------------------------- ### Initialize Migrondi Database Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Initialize the Migrondi database by creating the migrations tracking table if it doesn't exist. This operation is safe to call multiple times. ```fsharp // Synchronous migrondi.Initialize() // Asynchronous migrondi.InitializeAsync() |> Async.AwaitTask ``` -------------------------------- ### Basic Migrondi JSON Configuration Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/configuration.md This is a standard migrondi.json file. It specifies the database connection string, the directory for migrations, the name of the migration table, and the database driver. ```json { "connection": "Data Source=./migrondi.db", "migrations": "./migrations", "tableName": "__migrondi_migrations", "driver": "sqlite" } ``` -------------------------------- ### Create New Migration File Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/cli.md Use the 'new' command followed by a migration name to generate a new SQL migration file. The file will follow the naming convention {timestamp}_{name}.sql. ```bash $ migrondi new create-users-table [22:00:58 INF] Creating a new migration with name: create-users-table. [22:00:58 INF] Migration create-users-table_1695873658869.sql created successfully. ``` -------------------------------- ### Format and Lint Source Code Source: https://github.com/angelmunoz/migrondi/blob/vnext/AGENTS.md Commands to format F# source files using Fantomas. ```bash # Format all F# source files dotnet fsi build.fsx format # Or directly dotnet fantomas format ``` -------------------------------- ### Build Migrondi as a Self-Contained Single File Executable Source: https://github.com/angelmunoz/migrondi/blob/vnext/README.md This command publishes Migrondi as a self-contained, single-file executable for a specified runtime identifier (RID). Replace with the appropriate value for your target platform. ```bash dotnet publish -c Release -r --self-contained true -p:PublishSingleFile=true -o dist ``` -------------------------------- ### Check Migration Status with CLI Source: https://context7.com/angelmunoz/migrondi/llms.txt Use the `migrondi status` command to verify if a specific migration file has been applied to the database. ```bash migrondi status 1695873658869_create-users-table.sql ``` -------------------------------- ### Apply Pending Migrations Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/cli.md Execute the `migrondi up` command to apply all pending migrations to the database. The output shows which migrations are being run and confirms successful application. ```text $ migrondi up [22:10:01 INF] Running '1' migrations. [22:10:01 INF] Applied migration 'create-users-table_1695873658869' successfully. ``` -------------------------------- ### Create Migrondi Service Instance Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Use MigrondiFactory to create a service instance with a configuration object. Optionally provide a custom logger. ```fsharp open Migrondi.Core let config = { MigrondiConfig.Default with connection = "Data Source=./migrondi.db" migrations = "./migrations" driver = MigrondiDriver.Sqlite } // Create service with default local file system source let migrondi = Migrondi.MigrondiFactory(config, ".") // Optionally, provide a custom logger open Microsoft.Extensions.Logging let logger = LoggerFactory.Create(fun builder -> builder.AddConsole() |> ignore) .CreateLogger() let migrondi = Migrondi.MigrondiFactory(config, ".", logger = logger) ``` -------------------------------- ### Create New Migration File Source: https://context7.com/angelmunoz/migrondi/llms.txt Generates a new SQL migration file with a timestamped name. Use `--manual-transaction` for operations not supporting automatic transactions. ```bash # Create a new migration migrondi new create-users-table # Create migration without automatic transaction (for operations like CREATE INDEX CONCURRENTLY) migrondi new create-index-concurrently --manual-transaction ``` -------------------------------- ### Create New Migration Files Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Generate new migration files with up and down SQL content. If content is omitted, default templates are used. Supports both synchronous and asynchronous operations. ```fsharp // Synchronous let migration = migrondi.RunNew( "create-users-table", upContent = "CREATE TABLE users (id INT, name VARCHAR(255));", downContent = "DROP TABLE users;" ) // Asynchronous let! migration = migrondi.RunNewAsync( "create-users-table", upContent = "CREATE TABLE users (id INT, name VARCHAR(255));", downContent = "DROP TABLE users;" ) let migration = migrondi.RunNew("create-users-table") ``` -------------------------------- ### Preview migrations with DryRunDown Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Use DryRunDown to inspect migrations that would be rolled back without executing the rollback. ```fsharp let toRollback = migrondi.DryRunDown() for migration in toRollback do printfn "Would rollback: %s" migration.name printfn "SQL: %s" migration.downContent ``` -------------------------------- ### Run Migrondi Commands Source: https://github.com/angelmunoz/migrondi/blob/vnext/CONTRIBUTING.md Execute Migrondi commands such as 'new', 'up', or other available commands using the dotnet CLI. ```sh dotnet run --project src/Migrondi -- ``` -------------------------------- ### Verify Applied Migrations Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/cli.md After applying migrations, run `migrondi list` again to confirm that the migrations have been marked as applied in the status. ```text $ migrondi list All Migrations ┌─────────┬──────────────────────────────────┬──────────────────────────────────┐ │ Status │ Name │ Date Created │ ├─────────┼──────────────────────────────────┼──────────────────────────────────┤ │ Applied │ create-users-table_1695873658869 │ 27/09/2023 10:00:58 p. m. -06:00 │ └─────────┴──────────────────────────────────┴──────────────────────────────────┘ ``` -------------------------------- ### Run Migrondi Tests Source: https://github.com/angelmunoz/migrondi/blob/vnext/AGENTS.md Commands to execute test suites using dotnet test or FsMake. ```bash # Run all tests dotnet test src/Migrondi.Tests --no-restore # Run tests using FsMake dotnet fsi build.fsx test # Run single test dotnet test src/Migrondi.Tests --filter "FullyQualifiedName=Namespace.ClassName.MethodName" # Run tests for specific framework dotnet test src/Migrondi.Tests -f net8.0 --no-restore ``` -------------------------------- ### Create Migrations Programmatically in F# Source: https://context7.com/angelmunoz/migrondi/llms.txt Generate new migration files using the `RunNew` method, providing SQL content for `up` and `down` operations. Supports automatic transactions by default, with an option for manual transaction control. ```fsharp // Create migration with content let migration = migrondi.RunNew( "create-users-table", upContent = "CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(255), email VARCHAR(255));", downContent = "DROP TABLE users;" ) // Create migration with default templates let migration = migrondi.RunNew("create-products-table") // Create migration without automatic transaction let migration = migrondi.RunNew( "create-index-concurrently", upContent = "CREATE INDEX CONCURRENTLY idx_users_email ON users(email);", downContent = "DROP INDEX CONCURRENTLY IF EXISTS idx_users_email;", manualTransaction = true ) // Async version let! migration = migrondi.RunNewAsync( "create-orders-table", upContent = "CREATE TABLE orders (id INT PRIMARY KEY, user_id INT);", downContent = "DROP TABLE orders;" ) ``` -------------------------------- ### SQL Server Connection String Configuration Source: https://context7.com/angelmunoz/migrondi/llms.txt JSON configuration for connecting to a SQL Server database. ```json { "connection": "Server=localhost;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=true", "driver": "mssql" } ``` -------------------------------- ### Async API Methods Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Reference for asynchronous equivalents of core migration methods. ```APIDOC ## Async API Reference ### Description All core methods have async equivalents that support optional CancellationToken. ### Methods - InitializeAsync - RunNewAsync - RunUpAsync - RunDownAsync - DryRunUpAsync - DryRunDownAsync - MigrationsListAsync - ScriptStatusAsync ### Parameters #### Query Parameters - **cancellationToken** (CancellationToken) - Optional - Token to cancel the asynchronous operation. ``` -------------------------------- ### Restore Dependencies Source: https://github.com/angelmunoz/migrondi/blob/vnext/AGENTS.md Command to restore project dependencies. ```bash dotnet restore ``` -------------------------------- ### PostgreSQL Connection String Configuration Source: https://context7.com/angelmunoz/migrondi/llms.txt JSON configuration for connecting to a PostgreSQL database. ```json { "connection": "Host=localhost;Database=myapp;Username=user;Password=pass", "driver": "postgresql" } ``` -------------------------------- ### MySQL Connection String Configuration Source: https://context7.com/angelmunoz/migrondi/llms.txt JSON configuration for connecting to a MySQL database. ```json { "connection": "Server=localhost;Database=myapp;User=root;Password=pass", "driver": "mysql" } ``` -------------------------------- ### Apply Pending Migrations in F# Source: https://context7.com/angelmunoz/migrondi/llms.txt Execute pending migrations using `RunUp`. This can apply all pending migrations, a specified number, or perform a dry run to preview changes without applying them. An asynchronous version with cancellation support is also provided. ```fsharp // Apply all pending migrations let applied = migrondi.RunUp() printfn "Applied %d migrations" applied.Count // Apply specific number of migrations let applied = migrondi.RunUp(amount = 3) // Dry run - preview without applying let pending = migrondi.DryRunUp() for migration in pending do printfn "Would apply: %s" migration.name printfn "SQL:\n%s" migration.upContent // Async version with cancellation open System.Threading let cts = new CancellationTokenSource(TimeSpan.FromSeconds(30.0)) let! applied = migrondi.RunUpAsync(cancellationToken = cts.Token) ``` -------------------------------- ### SQLite Connection String Configuration Source: https://context7.com/angelmunoz/migrondi/llms.txt JSON configuration for connecting to a SQLite database. ```json { "connection": "Data Source=./migrondi.db", "driver": "sqlite" } ``` -------------------------------- ### Handle Migration Errors in F# Source: https://context7.com/angelmunoz/migrondi/llms.txt Implement robust error handling for migration-specific exceptions like `SetupDatabaseFailed`, `MigrationApplicationFailed`, `MigrationRollbackFailed`, `SourceNotFound`, `DeserializationFailed`, and `MalformedSource`. ```fsharp try migrondi.RunUp() with | :? SetupDatabaseFailed -> printfn "Failed to initialize database" | :? MigrationApplicationFailed as ex -> printfn "Failed to apply migration: %s" ex.Migration.name // Migration was automatically rolled back | :? MigrationRollbackFailed as ex -> printfn "Failed to rollback migration: %s" ex.Migration.name | :? SourceNotFound as ex -> printfn "Migration file not found: %s at %s" ex.name ex.path | :? DeserializationFailed as ex -> printfn "Failed to parse: %s - %s" ex.Content ex.Reason | :? MalformedSource as ex -> printfn "Malformed migration %s: %s" ex.SourceName ex.Reason ``` -------------------------------- ### Handle Migrondi exceptions Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Catch specific exceptions like MigrationApplicationFailed or SourceNotFound to handle errors during migration execution. ```fsharp try migrondi.RunUp() with | :? MigrationApplicationFailed as ex -> printfn "Failed to apply migration: %s" ex.Message // Migration was rolled back automatically | :? SourceNotFound as ex -> printfn "Migration not found: %s" ex.Message | ex -> printfn "Unexpected error: %s" ex.Message ``` -------------------------------- ### Apply Pending Migrations (Up) Source: https://context7.com/angelmunoz/migrondi/llms.txt Applies all pending database migrations. Can specify a number of migrations to apply or perform a dry run. ```bash # Apply all pending migrations migrondi up # Apply specific number of migrations migrondi up 3 # Dry run - preview without applying migrondi up --dry ``` -------------------------------- ### Configure Migrondi PATH for Windows PowerShell Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/index.md Add this to your PowerShell profile file (accessed via 'code $profile') to make Migrondi available globally. This sets the MIGRONDI_HOME environment variable and appends it to the PATH. ```powershell # you can put this at the end of your $profile file $env:MIGRONDI_HOME="$HOME/Apps/migrondi" $env:PATH += ";$env:MIGRONDI_HOME" ``` -------------------------------- ### DryRunDown Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Previews migrations that would be rolled back without actually executing the rollback. ```APIDOC ## DryRunDown ### Description Previews migrations that would be rolled back without actually executing the rollback. ### Method DryRunDown() ### Response - **List** - A list of migration objects containing name and downContent. ``` -------------------------------- ### SQL Migration with Manual Transaction Header Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/cli.md Manually enable manual transactions by including the `-- MIGRONDI:ManualTransaction=true` header in your SQL migration file. This header must appear before your SQL code. ```sql -- MIGRONDI:NAME=create-users-table_1695873658869.sql -- MIGRONDI:TIMESTAMP=1695873658869 -- ---------- MIGRONDI:UP ---------- create table users ( id integer primary key, name text not null, email text not null, password text not null, created_at datetime not null, updated_at datetime not null ); -- ---------- MIGRONDI:DOWN ---------- drop table users; ``` -------------------------------- ### Check migration status Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Verify if a specific migration file has been applied or is still pending. ```fsharp let status = migrondi.ScriptStatus("1708216610033_create-users-table.sql") match status with | Applied migration -> printfn "Migration applied: %s" migration.name | Pending migration -> printfn "Migration pending: %s" migration.name ``` -------------------------------- ### Check Migration Status Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/cli.md Use the `migrondi list` command to view the status of all migrations, indicating which are pending or applied. This helps in understanding the current state of your database schema. ```text $ migrondi list All Migrations ┌─────────┬──────────────────────────────────┬──────────────────────────────────┐ │ Status │ Name │ Date Created │ ├─────────┼──────────────────────────────────┼──────────────────────────────────┤ │ Pending │ create-users-table_1695873658869 │ 27/09/2023 10:00:58 p. m. -06:00 │ └─────────┴──────────────────────────────────┴──────────────────────────────────┘ ``` -------------------------------- ### Use asynchronous API with cancellation Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md All methods have async equivalents that support optional CancellationToken for task management. ```fsharp open System.Threading let cancellationToken = new CancellationTokenSource(5000).Token let! migrations = migrondi.MigrationsListAsync(cancellationToken) ``` -------------------------------- ### V0 Migration File Format (Deprecated) Source: https://context7.com/angelmunoz/migrondi/llms.txt The deprecated V0 migration file format uses a filename pattern of `{name}_{timestamp}.sql` and has a different comment structure for UP and DOWN sections. ```sql -- ---------- MIGRONDI:UP:1695829818636 ---------- create table users (id integer primary key); -- ---------- MIGRONDI:DOWN ---------- drop table users; ``` -------------------------------- ### V1 Migration File Format Source: https://context7.com/angelmunoz/migrondi/llms.txt The current V1 migration file format uses a filename pattern of `{timestamp}_{name}.sql` and includes metadata comments for name, timestamp, and transaction settings. ```sql -- MIGRONDI:NAME=1695829818636_CreateUsersTable.sql -- MIGRONDI:TIMESTAMP=1695829818636 -- MIGRONDI:ManualTransaction=true -- ---------- MIGRONDI:UP ---------- create table users ( id integer primary key, name text not null, email text not null unique, password text not null, created_at datetime not null, updated_at datetime not null ); create index idx_users_email on users(email); -- ---------- MIGRONDI:DOWN ---------- drop index if exists idx_users_email; drop table users; ``` -------------------------------- ### List Migration Status in F# Source: https://context7.com/angelmunoz/migrondi/llms.txt Retrieve the status of all migrations to identify applied and pending ones. An asynchronous version is available. You can also check the status of a specific migration script. ```fsharp // Get all migrations with status let migrations = migrondi.MigrationsList() for migration in migrations do match migration with | Applied m -> printfn "Applied: %s (timestamp: %d)" m.name m.timestamp | Pending m -> printfn "Pending: %s (timestamp: %d)" m.name m.timestamp // Async version let! migrations = migrondi.MigrationsListAsync() // Check specific migration status let status = migrondi.ScriptStatus("1708216610033_create-users-table.sql") match status with | Applied m -> printfn "Migration is applied" | Pending m -> printfn "Migration is pending" ``` -------------------------------- ### Create Migration Without Automatic Transaction Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Create a migration without Migrondi automatically handling transactions. Set `manualTransaction` to `true` for scenarios like `CREATE INDEX CONCURRENTLY`. ```fsharp // Create migration without automatic transaction handling let migration = migrondi.RunNew( "create-index-concurrently", upContent = "CREATE INDEX CONCURRENTLY idx_users_email ON users(email);", downContent = "DROP INDEX CONCURRENTLY IF EXISTS idx_users_email;", manualTransaction = true ) ``` -------------------------------- ### V1 Migration File Format Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/cli.md This is the V1 format for migration files, which is the current standard. It includes required headers for name and timestamp, and an optional header for manual transaction control. The UP and DOWN sections are used for migration and rollback SQL code. ```sql -- MIGRONDI:NAME=create-users-table_1695873658869.sql -- MIGRONDI:TIMESTAMP=1695873658869 -- ---------- MIGRONDI:UP ---------- -- Add your SQL migration code below. You can delete this line but do not delete the comments above. -- ---------- MIGRONDI:DOWN ---------- -- Add your SQL rollback code below. You can delete this line but do not delete the comment above. ``` -------------------------------- ### Apply Pending Migrations Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Apply all pending migrations to the database. You can also specify the number of migrations to apply. Supports asynchronous execution. ```fsharp // Apply all pending migrations migrondi.RunUp() // Apply specific number of migrations migrondi.RunUp(amount = 3) // Asynchronous migrondi.RunUpAsync() |> Async.AwaitTask migrondi.RunUpAsync(amount = 3) |> Async.AwaitTask ``` -------------------------------- ### Rollback Migrations in F# Source: https://context7.com/angelmunoz/migrondi/llms.txt Revert applied migrations using `RunDown`. This allows rolling back the last migration, a specific number of migrations, or performing a dry run to preview which migrations would be reverted. An asynchronous version is available. ```fsharp // Rollback last migration let reverted = migrondi.RunDown() // Rollback specific number of migrations let reverted = migrondi.RunDown(amount = 2) // Dry run - preview without rolling back let toRollback = migrondi.DryRunDown() for migration in toRollback do printfn "Would rollback: %s" migration.name printfn "SQL:\n%s" migration.downContent // Async version let! reverted = migrondi.RunDownAsync(amount = 1) ``` -------------------------------- ### ScriptStatus Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Checks the application status of a specific migration file. ```APIDOC ## ScriptStatus ### Description Checks if a specific migration has been applied or is pending. ### Method ScriptStatus(string filename) ### Parameters #### Path Parameters - **filename** (string) - Required - The name of the migration file to check. ### Response - **MigrationStatus** - Returns either Applied or Pending status. ``` -------------------------------- ### Create Migration with Manual Transaction Flag Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/cli.md Use the `--manual-transaction` flag when creating a new migration to disable automatic transaction wrapping. This is useful for operations that cannot be performed within a transaction. ```bash $ migrondi new create-index-concurrently --manual-transaction ``` -------------------------------- ### SQLite Path Resolution in Migrondi JSON Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/configuration.md When using SQLite with a relative connection string, Migrondi resolves the database path relative to the project's root directory. Absolute paths are not modified. ```json { "connection": "Data Source=./migrondi.db", "migrations": "./migrations", "driver": "sqlite" } ``` -------------------------------- ### List Migrations Status Source: https://context7.com/angelmunoz/migrondi/llms.txt Displays the current status of all migrations, including applied and pending ones. Can filter by 'up' or 'down' status. ```bash # List all migrations migrondi list # List only pending (up) migrations migrondi list up # List only applied (down) migrations migrondi list down ``` -------------------------------- ### Revert Last Migration Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/cli.md Use the `migrondi down` command to revert the most recently applied migration. The command output indicates the migration being reverted and confirms its successful rollback. ```text $ migrondi down [22:11:01 INF] Running '1' migrations. [22:11:01 INF] Reverted migration 'create-users-table_1695873658869' successfully. ``` -------------------------------- ### Rollback Applied Migrations (Down) Source: https://context7.com/angelmunoz/migrondi/llms.txt Reverts applied database migrations. Can specify the number of migrations to rollback or perform a dry run. ```bash # Rollback last migration migrondi down # Rollback specific number of migrations migrondi down 2 # Dry run - preview without rolling back migrondi down --dry ``` -------------------------------- ### List Migration Status Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Retrieve the status of all migrations, indicating whether they are applied or pending. Supports both synchronous and asynchronous operations. ```fsharp // Synchronous let migrations = migrondi.MigrationsList() // Asynchronous let! migrations = migrondi.MigrationsListAsync() // Example usage for iterating through migration statuses for migration in migrations do match migration with | Applied m -> printfn "Applied: %s" m.name | Pending m -> printfn "Pending: %s" m.name ``` -------------------------------- ### Rollback Applied Migrations Source: https://github.com/angelmunoz/migrondi/blob/vnext/docs/services/migrondi.md Revert applied migrations. You can rollback the last migration or a specific number of migrations. Supports asynchronous execution. ```fsharp // Rollback last migration migrondi.RunDown() // Rollback specific number of migrations migrondi.RunDown(amount = 2) // Asynchronous migrondi.RunDownAsync() |> Async.AwaitTask ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.