3. Configuring - Genato/ONTO GitHub Wiki

There are few steps before we can run application.

  • Download project and build it (Don't run !!).
  • Open **PgAdmin **-> right click on postgres databse and then click Query Tool and write query create extension "uuid-ossp"; to enable automatic generating of guids.
  • Create database
    • Right click on postgres database open Query Tool... and copy paste
    CREATE DATABASE "ONTO"
  • Create and configure user/role
    • Right click on postgres database open Query Tool... and copy paste
    CREATE ROLE onto LOGIN
    PASSWORD 'onto'
    NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;

    GRANT ALL PRIVILEGES ON DATABASE "ONTO" TO onto;

    CREATE ROLE onto_identity LOGIN
    PASSWORD 'onto_identity'
    NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;

    GRANT ALL PRIVILEGES ON DATABASE "ONTO" TO onto_identity
  • Open Package Manager Console in Visual Studio
    • Update database (this will create database and all tables)
      • Update-Database -ConfigurationTypeName ONTO.Migrations.IdentityMigrations.Configuration
      • Update-Database -ConfigurationTypeName ONTO.Migrations.ONTOMigrations.Configuration

Run next statements in pgAdmin->ONTO->Query Tool

  • Create dumy admin user (if you want create your own admin user)
INSERT INTO "identity"."Users"(
	"UserId", "Email", "EmailConfirmed", "PasswordHash", "SecurityStamp", "PhoneNumber", "PhoneNumberConfirmed", "TwoFactorEnabled", "LockoutEndDateUtc", "LockoutEnabled", "AccessFailedCount", "UserName")
	VALUES ('ffe98ac6-d0bc-4416-b73b-ce754434d2f1', '[email protected]', false, 'AMpM2RjsG4y7ebsy0Z/gJwU8dymzZ9DmjKH+BQ5sEtuHPrdVQ/vjQKmWpzQzSV9IlQ==', 'c96f2389-cc01-4241-87f7-ee97641f944e', null, false, false, null, true, 0, '[email protected]');
  • Create role and add user to role
INSERT INTO "identity"."Roles" ("Id", "Name", "Discriminator") VALUES ('e9d34da8-f423-4a74-8c74-2972c7669bbf', 'Admin', 'OntoIdentityRole');

INSERT INTO "identity"."UserRoles"("UserId", "RoleId") VALUES ('ffe98ac6-d0bc-4416-b73b-ce754434d2f1', 'e9d34da8-f423-4a74-8c74-2972c7669bbf');
  • Create default languages (localization)
INSERT INTO "onto"."Localization" ("ID", "Localization") VALUES (1, 'hr');
INSERT INTO "onto"."Localization" ("ID", "Localization") VALUES (2, 'en');
  • Create user settings for previously created user
INSERT INTO onto."User_Settings"("ID", "UserID", "LocalizationID") VALUES (0, 'ffe98ac6-d0bc-4416-b73b-ce754434d2f1', 1);

You'r ready to go, run the application :)


NOTE:
Whenever you add new class/Model just put property public DbSet<NewModel> PropertyName { get; set; } in one of the DbContext classes and repeat Add migrations and Update database steps.
If you add new property to already existing class/Model or if you change name or some other attribute on property just repeat Add migrations and Update database steps.

Helper code (Pay attention what migration you use because there are two schemes)

  • Enable migrations
    • Enable-Migrations -ContextTypeName IdentityUserDbContext -MigrationsDirectory Migrations\IdentityMigrations
    • Enable-Migrations -ContextTypeName OntoDbContext -MigrationsDirectory Migrations\ONTOMigrations
  • Add migrations
    • Add-Migration -ConfigurationTypeName ONTO.Migrations.IdentityMigrations.Configuration "some_migration_name"
    • Add-Migration -ConfigurationTypeName ONTO.Migrations.ONTOMigrations.Configuration "some_migration_name"
  • Update database
    • Update-Database -ConfigurationTypeName ONTO.Migrations.IdentityMigrations.Configuration
    • Update-Database -ConfigurationTypeName ONTO.Migrations.ONTOMigrations.Configuration
⚠️ **GitHub.com Fallback** ⚠️