private void MigrateDatabase(IApplicationBuilder app) { var genreConfiguration = Configuration.GetSection("Genre").Get <GenreConfiguration>(); var userConfiguration = Configuration.GetSection("User").Get <UserConfiguration>(); var movieConfiguration = Configuration.GetSection("Movie").Get <MovieConfiguration>(); //var movieGenreConfiguration = Configuration.GetSection("MovieGenre").Get<MovieGenreConfiguration>(); var permissionConfiguration = Configuration.GetSection("Permission").Get <PermissionConfiguration>(); var reservationConfiguration = Configuration.GetSection("Reservation").Get <ReservationConfiguration>(); var roomConfiguration = Configuration.GetSection("Room").Get <RoomConfiguration>(); var roomPlanConfiguration = Configuration.GetSection("RoomPlan").Get <RoomPlanConfiguration>(); var scheduleConfiguration = Configuration.GetSection("Schedule").Get <ScheduleConfiguration>(); var scheduleSlotConfiguration = Configuration.GetSection("ScheduleSlot").Get <ScheduleSlotConfiguration>(); var seatTypeConfiguration = Configuration.GetSection("SeatType").Get <SeatTypeConfiguration>(); var seatPositionConfiguration = Configuration.GetSection("SeatPosition").Get <SeatPositionConfiguration>(); var locationConfiguration = Configuration.GetSection("Location").Get <LocationConfiguration>(); var roomAssignmentConfiguration = Configuration.GetSection("RoomAssignment").Get <RoomAssignmentConfiguration>(); var roomTechnologyConfiguration = Configuration.GetSection("RoomTechnology").Get <RoomTechnologyConfiguration>(); using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var context = serviceScope.ServiceProvider.GetRequiredService <DatabaseContext>(); context.Database.Migrate(); GenreSeed.Seed(context, genreConfiguration.Genres); UserSeed.Seed(context, userConfiguration.Users); PermissionSeed.Seed(context, permissionConfiguration.Permissions); SeatTypeSeed.Seed(context, seatTypeConfiguration.SeatTypes); LocationSeed.Seed(context, locationConfiguration.Locations); RoomTechnologySeed.Seed(context, roomTechnologyConfiguration.RoomTechnologies); } }
//This class tells Entity Framework where our seed files are, //and to use them to add records to our operational database. //We do them in this order so that foreign keys can be established. protected override async void Seed(OracleContext context) { //System-specific context.Users.AddOrUpdate(UserSeed.ToArray()); await context.SaveChangesAsync(); context.Permissions.AddOrUpdate(PermissionSeed.ToArray()); await context.SaveChangesAsync(); //Operational context.Campuses.AddOrUpdate(CampusSeed.ToArray()); await context.SaveChangesAsync(); context.Countries.AddOrUpdate(CountrySeed.ToArray()); await context.SaveChangesAsync(); context.AcademicYears.AddOrUpdate(AcademicYearSeed.ToArray()); await context.SaveChangesAsync(); context.Modules.AddOrUpdate(ModuleSeed.ToArray()); await context.SaveChangesAsync(); context.Courses.AddOrUpdate(CourseSeed.ToArray()); await context.SaveChangesAsync(); context.CourseModules.AddOrUpdate(CourseModuleSeed.ToArray()); await context.SaveChangesAsync(); context.Lecturers.AddOrUpdate(LecturerSeed.ToArray()); await context.SaveChangesAsync(); context.ModuleRuns.AddOrUpdate(ModuleRunSeed.ToArray()); await context.SaveChangesAsync(); context.Students.AddOrUpdate(StudentSeed.ToArray()); await context.SaveChangesAsync(); context.Enrollments.AddOrUpdate(EnrollmentSeed.ToArray()); await context.SaveChangesAsync(); context.Assignments.AddOrUpdate(AssignmentSeed.ToArray()); await context.SaveChangesAsync(); context.Results.AddOrUpdate(ResultSeed.ToArray()); await context.SaveChangesAsync(); context.Graduations.AddOrUpdate(GraduationSeed.ToArray()); await context.SaveChangesAsync(); context.Complaints.AddOrUpdate(ComplaintSeed.ToArray()); await context.SaveChangesAsync(); }
/// <summary> /// Method to set seeds into database. /// </summary> public static void SetSeeds() { using var db = new SSOContext(); if (!db.Users.Any()) { CompanySeed.SetSeeds(db); PermissionSeed.SetSeeds(db); UserSeed.SetSeeds(db); RoleSeed.SetSeeds(db); UserParamsSeed.SetSeeds(db); RolePermissionSeed.SetSeeds(db); UserRoleSeed.SetSeeds(db); CompanyAirportsSeed.SetSeeds(db); } }
/** * dotnet ef migrations add InitialCreate --context SitPostgreSQLContext --output Data/Migrations/SitDb * dotnet ef migrations script --context SitPostgreSQLContext * * * Add-Migration SitDbInit -context SitPostgreSQLContext -output Data/Migrations/SitDb * Add-Migration EventSourcingDbInit -context EventStoreEventSourcingContext -output Data/Migrations/EventSourcingDb **/ private static async Task EnsureSeedData <TSitContext>(IServiceProvider services) where TSitContext : DbContext { using var scope = services.GetRequiredService <IServiceScopeFactory>().CreateScope(); //Administração Pessoa Seed. //var adminPessoaDbContext = scope.ServiceProvider.GetRequiredService<TSitContext>(); //await AdministracaoPessoaSeed.EnsureSeedData(adminPessoaDbContext); //Identity Seed // var userManager = scope.ServiceProvider.GetRequiredService<IUserManager>(); // var roleManager = scope.ServiceProvider.GetRequiredService<IRoleManager>(); // var dbContext = scope.ServiceProvider.GetRequiredService<TSitContext>(); await PermissionSeed.EnsureSeedData <TSitContext>(services); await IdentitySeed.EnsureSeedData <TSitContext>(services); await PessoaSeed.EnsureSeedData <TSitContext>(services); }