diff --git a/src/Altinn.Profile.Integrations/Migration/profiledb.sql b/src/Altinn.Profile.Integrations/Migration/profiledb.sql new file mode 100644 index 0000000..c2382ae --- /dev/null +++ b/src/Altinn.Profile.Integrations/Migration/profiledb.sql @@ -0,0 +1,42 @@ +-- Create schema if it doesn't exist +CREATE SCHEMA IF NOT EXISTS contact_and_reservation; + +-- Grant access to the schema +GRANT ALL ON SCHEMA contact_and_reservation TO platform_profile_admin; +GRANT USAGE ON SCHEMA contact_and_reservation TO platform_profile; + +-- Create table MailboxSupplier +CREATE TABLE IF NOT EXISTS contact_and_reservation.mailbox_supplier ( + mailbox_supplier_id INT GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY, + org_number_ak CHAR(9) NOT NULL, + CONSTRAINT unique_org_number_ak UNIQUE (org_number_ak) +); + +-- Create table Metadata +CREATE TABLE IF NOT EXISTS contact_and_reservation.metadata ( + latest_change_number BIGINT PRIMARY KEY, + exported TIMESTAMPTZ +); + +-- Create table Person +CREATE TABLE IF NOT EXISTS contact_and_reservation.person ( + contact_and_reservation_user_id INT GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY, + fnumber_ak CHAR(11) NOT NULL UNIQUE, + reservation BOOLEAN, + description VARCHAR(20), + mobile_phone_number VARCHAR(20), + mobile_phone_number_last_updated TIMESTAMPTZ, + mobile_phone_number_last_verified TIMESTAMPTZ, + email_address VARCHAR(400), + email_address_last_updated TIMESTAMPTZ, + email_address_last_verified TIMESTAMPTZ, + mailbox_address VARCHAR(50), + mailbox_supplier_id_fk INT, + x509_certificate TEXT, + language_code CHAR(2) NULL, + CONSTRAINT fk_mailbox_supplier FOREIGN KEY (mailbox_supplier_id_fk) REFERENCES contact_and_reservation.mailbox_supplier (mailbox_supplier_id), + CONSTRAINT chk_language_code CHECK (language_code ~* '^[a-z]{2}$') +); + +-- Indexes for performance +CREATE INDEX idx_fnumber_ak ON contact_and_reservation.person (fnumber_ak); diff --git a/src/Altinn.Profile/Altinn.Profile.csproj b/src/Altinn.Profile/Altinn.Profile.csproj index e400a54..b853bdd 100644 --- a/src/Altinn.Profile/Altinn.Profile.csproj +++ b/src/Altinn.Profile/Altinn.Profile.csproj @@ -15,7 +15,8 @@ - + + diff --git a/src/Altinn.Profile/Models/DbContext/ProfiledbContext.cs b/src/Altinn.Profile/Models/DbContext/ProfiledbContext.cs new file mode 100644 index 0000000..657e01d --- /dev/null +++ b/src/Altinn.Profile/Models/DbContext/ProfiledbContext.cs @@ -0,0 +1,77 @@ +// This file has been auto generated by EF Core Power Tools. +#nullable disable + +using Microsoft.EntityFrameworkCore; + +namespace Altinn.Profile.Models; + +/// +/// Represents the database context for the profile database. +/// +public partial class ProfileDbContext : DbContext +{ + /// + /// Initializes a new instance of the class. + /// + /// The options to be used by a . + public ProfileDbContext(DbContextOptions options) + : base(options) + { + } + + /// + /// Gets or sets the representing the mailbox suppliers. + /// + public virtual DbSet MailboxSuppliers { get; set; } + + /// + /// Gets or sets the representing the metadata. + /// + public virtual DbSet Metadata { get; set; } + + /// + /// Gets or sets the representing the people. + /// + public virtual DbSet People { get; set; } + + /// + /// Configures the schema needed for the context. + /// + /// The builder being used to construct the model for this context. + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.MailboxSupplierId).HasName("mailbox_supplier_pkey"); + + entity.Property(e => e.MailboxSupplierId).UseIdentityAlwaysColumn(); + entity.Property(e => e.OrgNumberAk).IsFixedLength(); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.LatestChangeNumber).HasName("metadata_pkey"); + + entity.Property(e => e.LatestChangeNumber).ValueGeneratedNever(); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ContactAndReservationUserId).HasName("person_pkey"); + + entity.Property(e => e.ContactAndReservationUserId).UseIdentityAlwaysColumn(); + entity.Property(e => e.FnumberAk).IsFixedLength(); + entity.Property(e => e.LanguageCode).IsFixedLength(); + + entity.HasOne(d => d.MailboxSupplierIdFkNavigation).WithMany(p => p.People).HasConstraintName("fk_mailbox_supplier"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + /// + /// A partial method that can be used to configure the model further. + /// + /// The builder being used to construct the model for this context. + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +} diff --git a/src/Altinn.Profile/Models/MailboxSupplier.cs b/src/Altinn.Profile/Models/MailboxSupplier.cs new file mode 100644 index 0000000..9a9230c --- /dev/null +++ b/src/Altinn.Profile/Models/MailboxSupplier.cs @@ -0,0 +1,40 @@ +// This file has been auto generated by EF Core Power Tools. +#nullable disable + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +using Microsoft.EntityFrameworkCore; + +namespace Altinn.Profile.Models; + +/// +/// Represents a mailbox supplier in the contact and reservation schema. +/// +[Table("mailbox_supplier", Schema = "contact_and_reservation")] +[Index("OrgNumberAk", Name = "unique_org_number_ak", IsUnique = true)] +public partial class MailboxSupplier +{ + /// + /// Gets or sets the unique identifier for the mailbox supplier. + /// + [Key] + [Column("mailbox_supplier_id")] + public int MailboxSupplierId { get; set; } + + /// + /// Gets or sets the organization number of the mailbox supplier. + /// + [Required] + [Column("org_number_ak")] + [StringLength(9)] + public string OrgNumberAk { get; set; } + + /// + /// Gets or sets the collection of people associated with the mailbox supplier. + /// + [InverseProperty("MailboxSupplierIdFkNavigation")] + public virtual ICollection People { get; set; } = new List(); +} diff --git a/src/Altinn.Profile/Models/Metadata.cs b/src/Altinn.Profile/Models/Metadata.cs new file mode 100644 index 0000000..aa15bc4 --- /dev/null +++ b/src/Altinn.Profile/Models/Metadata.cs @@ -0,0 +1,28 @@ +// This file has been auto generated by EF Core Power Tools. +#nullable disable + +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Altinn.Profile.Models; + +/// +/// Represents metadata in the contact and reservation schema. +/// +[Table("metadata", Schema = "contact_and_reservation")] +public partial class Metadata +{ + /// + /// Gets or sets the latest change number. + /// + [Key] + [Column("latest_change_number")] + public long LatestChangeNumber { get; set; } + + /// + /// Gets or sets the date and time when the metadata was exported. + /// + [Column("exported")] + public DateTime? Exported { get; set; } +} diff --git a/src/Altinn.Profile/Models/Person.cs b/src/Altinn.Profile/Models/Person.cs new file mode 100644 index 0000000..14d90f7 --- /dev/null +++ b/src/Altinn.Profile/Models/Person.cs @@ -0,0 +1,117 @@ +// This file has been auto generated by EF Core Power Tools. +#nullable disable + +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +using Microsoft.EntityFrameworkCore; + +namespace Altinn.Profile.Models; +/// +/// Represents a person in the contact and reservation schema. +/// +[Table("person", Schema = "contact_and_reservation")] +[Index("FnumberAk", Name = "idx_fnumber_ak")] +[Index("FnumberAk", Name = "person_fnumber_ak_key", IsUnique = true)] +public partial class Person +{ + /// + /// Gets or sets the unique identifier for the contact and reservation user. + /// + [Key] + [Column("contact_and_reservation_user_id")] + public int ContactAndReservationUserId { get; set; } + + /// + /// Gets or sets the F-number (a unique identifier) of the person. + /// + [Required] + [Column("fnumber_ak")] + [StringLength(11)] + public string FnumberAk { get; set; } + + /// + /// Gets or sets a value indicating whether the person has a reservation. + /// + [Column("reservation")] + public bool? Reservation { get; set; } + + /// + /// Gets or sets the description of the person. + /// + [Column("description")] + [StringLength(20)] + public string Description { get; set; } + + /// + /// Gets or sets the mobile phone number of the person. + /// + [Column("mobile_phone_number")] + [StringLength(20)] + public string MobilePhoneNumber { get; set; } + + /// + /// Gets or sets the date and time when the mobile phone number was last updated. + /// + [Column("mobile_phone_number_last_updated")] + public DateTime? MobilePhoneNumberLastUpdated { get; set; } + + /// + /// Gets or sets the date and time when the mobile phone number was last verified. + /// + [Column("mobile_phone_number_last_verified")] + public DateTime? MobilePhoneNumberLastVerified { get; set; } + + /// + /// Gets or sets the email address of the person. + /// + [Column("email_address")] + [StringLength(400)] + public string EmailAddress { get; set; } + + /// + /// Gets or sets the date and time when the email address was last updated. + /// + [Column("email_address_last_updated")] + public DateTime? EmailAddressLastUpdated { get; set; } + + /// + /// Gets or sets the date and time when the email address was last verified. + /// + [Column("email_address_last_verified")] + public DateTime? EmailAddressLastVerified { get; set; } + + /// + /// Gets or sets the mailbox address of the person. + /// + [Column("mailbox_address")] + [StringLength(50)] + public string MailboxAddress { get; set; } + + /// + /// Gets or sets the foreign key to the mailbox supplier. + /// + [Column("mailbox_supplier_id_fk")] + public int? MailboxSupplierIdFk { get; set; } + + /// + /// Gets or sets the X.509 certificate of the person. + /// + [Column("x509_certificate")] + public string X509Certificate { get; set; } + + /// + /// Gets or sets the language code of the person. + /// + [Column("language_code")] + [StringLength(2)] + public string LanguageCode { get; set; } + + /// + /// Gets or sets the navigation property to the mailbox supplier. + /// + [ForeignKey("MailboxSupplierIdFk")] + [InverseProperty("People")] + public virtual MailboxSupplier MailboxSupplierIdFkNavigation { get; set; } +} diff --git a/src/Altinn.Profile/efpt.config.json b/src/Altinn.Profile/efpt.config.json new file mode 100644 index 0000000..ac5afc4 --- /dev/null +++ b/src/Altinn.Profile/efpt.config.json @@ -0,0 +1,54 @@ +{ + "CodeGenerationMode": 4, + "ContextClassName": "ProfileDbContext", + "ContextNamespace": null, + "FilterSchemas": false, + "IncludeConnectionString": false, + "ModelNamespace": null, + "OutputContextPath": null, + "OutputPath": "Models", + "PreserveCasingWithRegex": true, + "ProjectRootNamespace": "Altinn.Profile", + "Schemas": null, + "SelectedHandlebarsLanguage": 2, + "SelectedToBeGenerated": 0, + "T4TemplatePath": null, + "Tables": [ + { + "Name": "contact_and_reservation.mailbox_supplier", + "ObjectType": 0 + }, + { + "Name": "contact_and_reservation.metadata", + "ObjectType": 0 + }, + { + "Name": "contact_and_reservation.person", + "ObjectType": 0 + } + ], + "UiHint": null, + "UncountableWords": null, + "UseAsyncStoredProcedureCalls": true, + "UseBoolPropertiesWithoutDefaultSql": false, + "UseDatabaseNames": false, + "UseDateOnlyTimeOnly": true, + "UseDbContextSplitting": false, + "UseDecimalDataAnnotationForSprocResult": true, + "UseFluentApiOnly": false, + "UseHandleBars": false, + "UseHierarchyId": false, + "UseInflector": true, + "UseLegacyPluralizer": false, + "UseManyToManyEntity": false, + "UseNoDefaultConstructor": false, + "UseNoNavigations": false, + "UseNoObjectFilter": false, + "UseNodaTime": false, + "UseNullableReferences": false, + "UsePrefixNavigationNaming": false, + "UseSchemaFolders": false, + "UseSchemaNamespaces": false, + "UseSpatial": false, + "UseT4": false +} \ No newline at end of file