Alva

Alva

programmer
github
telegram
email

Abp Framework Unified Setting for Table Name Prefix and Schema

TL;DR Version:
To modify the table name prefix and schema of built-in tables in the Abp framework, follow these steps:

  1. Generate a template project using the CLI command abp new MyApp.
  2. Open the MyApp.EntityFrameworkCore project and delete the Migrations folder.
  3. In the MyApp.EntityFrameworkCore project, open the EntityFrameworkCore/MyAppDbContext.cs file.
  4. Find the OnModelCreating method and explore the builder.ConfigureXXX() methods to see the source code implementation.
  5. Modify the default configuration by setting the values of AbpCommonDbProperties.DbTablePrefix and AbpCommonDbProperties.DbSchema in the startup projects' Program.cs files and XXXDbContextFactory.cs file.
  6. Delete the Migrations folder in the XXX.EntityFrameworkCore project and run the XXX.DbMigrator project to generate migration files.
  7. Open the Migrations/MyAppDbContextModelSnapshot.cs file and verify that the generated migration code reflects the updated configuration.
  8. For special tables, such as those with the OpenIddict prefix, set the values of AbpOpenIddictDbProperties.DbTablePrefix and AbpOpenIddictDbProperties.DbSchema in the startup projects' Program.cs files and XXXDbContextFactory.cs file.
  9. Delete the Migrations folder, clear the database, and run the XXX.DbMigrator project to apply the migration.
  10. For individual configurations, find the corresponding configuration in the OnModelCreating method of the MyAppDbContext.cs file and set the values in the startup projects' Program.cs files and XXXDbContextFactory.cs file.
  11. Modify the table name prefix and schema of user tables in the MyApp.Domain project's MyAppConsts.cs file.

Detailed Version:
To modify the table name prefix and schema of built-in tables in the Abp framework, follow these steps:

  1. Generate a template project using the CLI command abp new MyApp.

  2. Open the MyApp.EntityFrameworkCore project and delete the Migrations folder. This folder contains the default migration files.

  3. In the MyApp.EntityFrameworkCore project, open the EntityFrameworkCore/MyAppDbContext.cs file. This file contains the configuration for the built-in tables.

  4. Find the OnModelCreating method in the MyAppDbContext.cs file. This method contains the configuration for the built-in tables.

  5. Explore the builder.ConfigureXXX() methods in the OnModelCreating method to see the source code implementation. These methods configure the tables and their prefixes and schemas.

  6. Modify the default configuration by setting the values of AbpCommonDbProperties.DbTablePrefix and AbpCommonDbProperties.DbSchema in the startup projects' Program.cs files and XXXDbContextFactory.cs file. These files are located in the startup projects (excluding XXX.DbMigrator).

  7. Delete the Migrations folder in the XXX.EntityFrameworkCore project. This folder contains the default migration files.

  8. Run the XXX.DbMigrator project to generate migration files based on the updated configuration.

  9. Open the Migrations/MyAppDbContextModelSnapshot.cs file and verify that the generated migration code reflects the updated configuration. The table name prefix and schema should be modified accordingly.

  10. For special tables, such as those with the OpenIddict prefix, set the values of AbpOpenIddictDbProperties.DbTablePrefix and AbpOpenIddictDbProperties.DbSchema in the startup projects' Program.cs files and XXXDbContextFactory.cs file. These files are located in the startup projects (excluding XXX.DbMigrator).

  11. Delete the Migrations folder, clear the database, and run the XXX.DbMigrator project to apply the migration. The special tables should now have the modified table name prefix and schema.

  12. For individual configurations, find the corresponding configuration in the OnModelCreating method of the MyAppDbContext.cs file. These configurations can be modified by setting the values in the startup projects' Program.cs files and XXXDbContextFactory.cs file. These files are located in the startup projects (excluding XXX.DbMigrator).

  13. Modify the table name prefix and schema of user tables in the MyApp.Domain project's MyAppConsts.cs file. The DbTablePrefix and DbSchema constants can be modified to reflect the desired values.

Note: Make sure to carefully follow the steps and verify the changes to ensure the correct modification of table name prefixes and schemas.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.