Open Closed

Option to Generate DB Scripts While Running The Migrator #5409


User avatar
0
viswajwalith created

If you're creating a bug/problem report, please include followings:

ABP Framework version: v5.1.3 UI type: MVC DB provider: EF Core / MongoDB Tiered (MVC) or Identity Server Separated (Angular): yes Exception message and stack trace: Steps to reproduce the issue:

We would like to Generate the SQL Files while execution of DB migrator to review the same, we are trying to enable the same but didn't find any supporting document for the same. Can you please provide the details for the same


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can run the dotnet ef migrations script command on the EF Core project to see the scripts.

    https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/applying?tabs=dotnet-core-cli#sql-scripts

  • User Avatar
    0
    viswajwalith created
    • That means do we need to generate for each micro service in this case?
    • don't we have an option out of box for the Migrator tool?
    • Do you think there will be a way to generate the scripts for all of the Micro services in one go?
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I think you can only use the dotnet ef migrations script to get the script on each project.

    The migratory tool just applies the migration and seeds the data.

  • User Avatar
    0
    viswajwalith created

    hi

    I think you can only use the dotnet ef migrations script to get the script on each project.

    The migratory tool just applies the migration and seeds the data.

    That's fine, we will generate manually for DB structural changes. but do we have any other way to generate the insert scripts for data seeding from the Migration tool right? Mainly for Permission, Roles and Tenant specific data.

    Also sometimes we are getting the Generated SQL file as empty, any idea on that? for the below code

    using System;
    using Microsoft.EntityFrameworkCore.Migrations;
    
    #nullable disable
    
    namespace XXXX.Migrations
    {
        public partial class ImportHistoryLogImportRunHistory : Migration
        {
            protected override void Up(MigrationBuilder migrationBuilder)
            {
                migrationBuilder.AddColumn<string>(
                    name: "CustomField1",
                    table: "EmployeeServiceImportRunHistories",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "CustomField2",
                    table: "EmployeeServiceImportRunHistories",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "CustomField3",
                    table: "EmployeeServiceImportRunHistories",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "CustomField4",
                    table: "EmployeeServiceImportRunHistories",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "CustomField5",
                    table: "EmployeeServiceImportRunHistories",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "RowNo",
                    table: "EmployeeServiceImportRunHistories",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "CustomField1",
                    table: "EmployeeServiceImportHistroyLogs",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "CustomField2",
                    table: "EmployeeServiceImportHistroyLogs",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "CustomField3",
                    table: "EmployeeServiceImportHistroyLogs",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "CustomField4",
                    table: "EmployeeServiceImportHistroyLogs",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "CustomField5",
                    table: "EmployeeServiceImportHistroyLogs",
                    type: "nvarchar(max)",
                    nullable: true);
    
                migrationBuilder.AddColumn<string>(
                    name: "RowNo",
                    table: "EmployeeServiceImportHistroyLogs",
                    type: "nvarchar(max)",
                    nullable: true);
            }
    
            protected override void Down(MigrationBuilder migrationBuilder)
            {
                migrationBuilder.DropColumn(
                    name: "CustomField1",
                    table: "EmployeeServiceImportRunHistories");
    
                migrationBuilder.DropColumn(
                    name: "CustomField2",
                    table: "EmployeeServiceImportRunHistories");
    
                migrationBuilder.DropColumn(
                    name: "CustomField3",
                    table: "EmployeeServiceImportRunHistories");
    
                migrationBuilder.DropColumn(
                    name: "CustomField4",
                    table: "EmployeeServiceImportRunHistories");
    
                migrationBuilder.DropColumn(
                    name: "CustomField5",
                    table: "EmployeeServiceImportRunHistories");
    
                migrationBuilder.DropColumn(
                    name: "RowNo",
                    table: "EmployeeServiceImportRunHistories");
    
                migrationBuilder.DropColumn(
                    name: "CustomField1",
                    table: "EmployeeServiceImportHistroyLogs");
    
                migrationBuilder.DropColumn(
                    name: "CustomField2",
                    table: "EmployeeServiceImportHistroyLogs");
    
                migrationBuilder.DropColumn(
                    name: "CustomField3",
                    table: "EmployeeServiceImportHistroyLogs");
    
                migrationBuilder.DropColumn(
                    name: "CustomField4",
                    table: "EmployeeServiceImportHistroyLogs");
    
                migrationBuilder.DropColumn(
                    name: "CustomField5",
                    table: "EmployeeServiceImportHistroyLogs");
    
                migrationBuilder.DropColumn(
                    name: "RowNo",
                    table: "EmployeeServiceImportHistroyLogs");
            }
        }
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    but do we have any other way to generate the insert scripts for data seeding from the Migration tool right? Mainly for Permission, Roles and Tenant specific data.

    You should use the Data Seed system.

    https://docs.abp.io/en/abp/latest/Data-Seeding

    Also sometimes we are getting the Generated SQL file as empty, any idea on that? for the below code

    You can rebuild the project and retry.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11