diff --git a/docs/en/Best-Practices/PostgreSQL-Integration.md b/docs/en/Best-Practices/PostgreSQL-Integration.md index 9b0bf40dc2..2f6dd03be7 100644 --- a/docs/en/Best-Practices/PostgreSQL-Integration.md +++ b/docs/en/Best-Practices/PostgreSQL-Integration.md @@ -9,27 +9,65 @@ - Replace the `AbpEntityFrameworkCoreSqlServerModule` with the `AbpEntityFrameworkCorePostgreSqlModule` - Replace the `options.UseSqlServer()` with the `options.UsePostgreSql()` - In other projects update the PostgreSQL connection string in necessary `appsettings.json` files + - more info of [PostgreSQL connection strings](https://www.connectionstrings.com/postgresql/),You need to pay attention to `Npgsql` in this document -#### Delete Existing Migrations +### EntityFrameworkCore.DbMigrations Project Update +- Update to use PostgreSQL in `XXXMigrationsDbContextFactory` + - Replace the `new DbContextOptionsBuilder().UseSqlServer()` with the `new DbContextOptionsBuilder().UseNpgsql()` + +### Delete Existing Migrations Delete all existing migration files (including `DbContextModelSnapshot`) ![postgresql-delete-initial-migrations](images/postgresql-delete-initial-migrations.png) -#### Regenerate Initial Migration & Update the Database +### Regenerate Initial Migration + +Set the correct startup project (usually a web project) + +![set-as-startup-project](../images/set-as-startup-project.png) -Set the correct startup project (usually a web project), -Open the **Package Manager Console** (Tools -> Nuget Package Manager -> Package Manager Console), select the `Acme.BookStore.EntityFrameworkCore.DbMigrations` as the **Default project** and execute the following command: +Open the **Package Manager Console** (Tools -> Nuget Package Manager -> Package Manager Console), select the `.EntityFrameworkCore.DbMigrations` as the **Default project** and execute the following command: Run `Add-Migration` command. ```` PM> Add-Migration Initial ```` -Then execute the `Update-Database` command to update the database schema: +### Update the Database + +You have two options to create the database. + +#### Using the DbMigrator Application + +The solution contains a console application (named `Acme.BookStore.DbMigrator` in this sample) that can create database, apply migrations and seed initial data. It is useful on development as well as on production environment. + +> `.DbMigrator` project has its own `appsettings.json`. So, if you have changed the connection string above, you should also change this one. + +Right click to the `.DbMigrator` project and select **Set as StartUp Project**: + +![set-as-startup-project](../images/set-as-startup-project.png) + +Hit F5 (or Ctrl+F5) to run the application. It will have an output like shown below: + +![set-as-startup-project](../images/db-migrator-app.png) + +#### Using EF Core Update-Database Command + +Ef Core has `Update-Database` command which creates database if necessary and applies pending migrations. + +Set the correct startup project (usually a web project) + +![set-as-startup-project](../images/set-as-startup-project.png) + +Open the **Package Manager Console** (Tools -> Nuget Package Manager -> Package Manager Console), select the `.EntityFrameworkCore.DbMigrations` as the **Default project** and execute the following command: ```` PM> Update-Database ```` +This will create a new database based on the configured connection string. + ![postgresql-update-database](images/postgresql-update-database.png) + +> Using the `.DbMigrator` tool is the suggested way, because it also seeds the initial data to be able to properly run the web application. diff --git a/npm/ng-packs/apps/dev-app/src/app/app.module.ts b/npm/ng-packs/apps/dev-app/src/app/app.module.ts index 0b2e9a93ec..f1324c233a 100644 --- a/npm/ng-packs/apps/dev-app/src/app/app.module.ts +++ b/npm/ng-packs/apps/dev-app/src/app/app.module.ts @@ -5,7 +5,6 @@ import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin'; import { NgxsModule } from '@ngxs/store'; -import { OAuthModule } from 'angular-oauth2-oidc'; import { environment } from '../environments/environment'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -19,7 +18,6 @@ import { SettingManagementConfigModule } from '@abp/ng.setting-management.config const LOGGERS = [NgxsLoggerPluginModule.forRoot({ disabled: false })]; @NgModule({ - declarations: [AppComponent], imports: [ CoreModule.forRoot({ environment, @@ -28,19 +26,18 @@ const LOGGERS = [NgxsLoggerPluginModule.forRoot({ disabled: false })]; }, }), ThemeSharedModule.forRoot(), - OAuthModule.forRoot(), - NgxsModule.forRoot([]), AccountConfigModule.forRoot({ redirectUrl: '/' }), IdentityConfigModule, TenantManagementConfigModule, SettingManagementConfigModule, + NgxsModule.forRoot(), BrowserModule, BrowserAnimationsModule, AppRoutingModule, SharedModule, - ...(environment.production ? [] : LOGGERS), ], + declarations: [AppComponent], bootstrap: [AppComponent], }) export class AppModule {} diff --git a/npm/ng-packs/packages/core/src/lib/core.module.ts b/npm/ng-packs/packages/core/src/lib/core.module.ts index a86ec5840d..67350b88ce 100644 --- a/npm/ng-packs/packages/core/src/lib/core.module.ts +++ b/npm/ng-packs/packages/core/src/lib/core.module.ts @@ -6,11 +6,14 @@ import { RouterModule } from '@angular/router'; import { NgxsRouterPluginModule } from '@ngxs/router-plugin'; import { NgxsStoragePluginModule } from '@ngxs/storage-plugin'; import { NgxsModule, NGXS_PLUGINS } from '@ngxs/store'; +import { OAuthModule } from 'angular-oauth2-oidc'; +import { AbstractNgModelComponent } from './abstracts/ng-model.component'; import { DynamicLayoutComponent } from './components/dynamic-layout.component'; import { RouterOutletComponent } from './components/router-outlet.component'; import { AutofocusDirective } from './directives/autofocus.directive'; import { InputEventDebounceDirective } from './directives/debounce.directive'; import { EllipsisDirective } from './directives/ellipsis.directive'; +import { ForDirective } from './directives/for.directive'; import { FormSubmitDirective } from './directives/form-submit.directive'; import { PermissionDirective } from './directives/permission.directive'; import { ClickEventStopPropagationDirective } from './directives/stop-propagation.directive'; @@ -19,20 +22,19 @@ import { ApiInterceptor } from './interceptors/api.interceptor'; import { ABP } from './models/common'; import { LocalizationPipe } from './pipes/localization.pipe'; import { SortPipe } from './pipes/sort.pipe'; +import { ConfigPlugin, NGXS_CONFIG_PLUGIN_OPTIONS } from './plugins/config.plugin'; import { LocaleProvider } from './providers/locale.provider'; import { ConfigState } from './states/config.state'; import { ProfileState } from './states/profile.state'; import { SessionState } from './states/session.state'; import { getInitialData, localeInitializer } from './utils/initial-utils'; -import { ConfigPlugin, NGXS_CONFIG_PLUGIN_OPTIONS } from './plugins/config.plugin'; -import { ForDirective } from './directives/for.directive'; -import { AbstractNgModelComponent } from './abstracts/ng-model.component'; @NgModule({ imports: [ NgxsModule.forFeature([ProfileState, SessionState, ConfigState]), - NgxsStoragePluginModule.forRoot({ key: 'SessionState' }), NgxsRouterPluginModule.forRoot(), + NgxsStoragePluginModule.forRoot({ key: ['SessionState'] }), + OAuthModule.forRoot(), CommonModule, HttpClientModule, FormsModule, diff --git a/templates/app/angular/src/app/app.module.ts b/templates/app/angular/src/app/app.module.ts index c700082cae..61312cd801 100644 --- a/templates/app/angular/src/app/app.module.ts +++ b/templates/app/angular/src/app/app.module.ts @@ -1,20 +1,19 @@ +import { AccountConfigModule } from '@abp/ng.account.config'; import { CoreModule } from '@abp/ng.core'; +import { IdentityConfigModule } from '@abp/ng.identity.config'; +import { SettingManagementConfigModule } from '@abp/ng.setting-management.config'; +import { TenantManagementConfigModule } from '@abp/ng.tenant-management.config'; import { LAYOUTS } from '@abp/ng.theme.basic'; +import { ThemeSharedModule } from '@abp/ng.theme.shared'; import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin'; import { NgxsModule } from '@ngxs/store'; -import { OAuthModule } from 'angular-oauth2-oidc'; import { environment } from '../environments/environment'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { SharedModule } from './shared/shared.module'; -import { ThemeSharedModule } from '@abp/ng.theme.shared'; -import { AccountConfigModule } from '@abp/ng.account.config'; -import { IdentityConfigModule } from '@abp/ng.identity.config'; -import { TenantManagementConfigModule } from '@abp/ng.tenant-management.config'; -import { SettingManagementConfigModule } from '@abp/ng.setting-management.config'; const LOGGERS = [NgxsLoggerPluginModule.forRoot({ disabled: false })]; @@ -31,8 +30,7 @@ const LOGGERS = [NgxsLoggerPluginModule.forRoot({ disabled: false })]; IdentityConfigModule, TenantManagementConfigModule, SettingManagementConfigModule, - OAuthModule.forRoot(), - NgxsModule.forRoot([]), + NgxsModule.forRoot(), BrowserModule, BrowserAnimationsModule, AppRoutingModule,