-
Notifications
You must be signed in to change notification settings - Fork 0
138 datasource entity ef migration #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bolsson
wants to merge
9
commits into
develop
Choose a base branch
from
138-datasource-entity-ef-migration
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7c3ef36
feat: add DataSource entity and EF migration (#138)
bolsson a429ba5
refactor: move DataSource to new Artskart3.Import project (#138)
bolsson 82b2331
Refactor import layer into Clean Architecture split (Import.Core + Im…
bolsson eb2165a
docs: update README with Import database setup and three-database arc…
bolsson 5b7239a
Merge branch 'develop' into 138-datasource-entity-ef-migration
DipakS100 32043cb
feat: add GbifDatasetDiscovery entity to Import bounded context (#138)
bolsson b9cdc08
Merge remote-tracking branch 'origin/develop' into 138-datasource-ent…
bolsson e68002d
#138 Added merge conflict aritifacts to gitignore file
bolsson a149fa8
Refine summary comment in DataSource class
bolsson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| using Artskart3.Import.Core.Domain.Enums; | ||
|
|
||
| namespace Artskart3.Import.Core.Domain.Entities; | ||
|
|
||
| /// <summary> | ||
| /// Provider configuration for a remote data source. | ||
| /// One flat table; use typed views or application-layer filtering to work with specific provider types. | ||
| /// </summary> | ||
| public class DataSource | ||
| { | ||
| public int Id { get; set; } | ||
|
|
||
| public string Name { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Discriminates the provider type and drives import pipeline branching. | ||
| /// </summary> | ||
| public ProviderType ProviderType { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// How many records to fetch per batch during harvest. | ||
| /// </summary> | ||
| public int RecordsBatchSize { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Web service API version (ArtskartDataDeliveryWebServiceV1 providers). | ||
| /// </summary> | ||
| public int WebServiceVersion { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// URL of the remote endpoint (web service or IPT archive base URL). | ||
| /// </summary> | ||
| public string? RemoteAddress { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// IPT archive filename, or local cache filename for GbifApi providers. | ||
| /// </summary> | ||
| public string? ArchiveName { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Internal notes for operators. | ||
| /// </summary> | ||
| public string? Notes { get; set; } | ||
|
|
||
| public bool IsDeleted { get; set; } | ||
|
|
||
| public bool IsEditedNameOrNotes { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Flags records from this source as having non-valid occurrence IDs. | ||
| /// </summary> | ||
| public bool NonValidOccurrenceIds { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// JSON predicate string used by GbifApi providers to query the GBIF occurrence API. | ||
| /// </summary> | ||
| public string? GbifApiQuery { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// JSON overrides applied during the harvest phase (field mapping / transformations). | ||
| /// </summary> | ||
| public string? HarvestPropertyOverrides { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// JSON overrides applied during the import/processing phase. | ||
| /// </summary> | ||
| public string? ImportPropertyOverrides { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// How often (in days) the source should be re-harvested. | ||
| /// </summary> | ||
| public int UpdateFrequencyInDays { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Digital Object Identifier — replaces GbifDataSetId from the old solution. | ||
| /// Required for active GbifIpt and GbifApi providers; enforced at the application layer. | ||
| /// </summary> | ||
| public string? Doi { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// GBIF publisher UUID. Used for API-based providers and publisher-scoped queries. | ||
| /// </summary> | ||
| public Guid? GbifPublisherId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Marks observations from this source as sensitive (restricted coordinates etc.). | ||
| /// </summary> | ||
| public bool IsSensitive { get; set; } | ||
|
|
||
| public DateTime CreatedAt { get; set; } = DateTime.UtcNow; | ||
| public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; | ||
| public DateTime? DeletedAt { get; set; } | ||
| } |
57 changes: 57 additions & 0 deletions
57
Artskart3.Import.Core/Domain/Entities/GbifDatasetDiscovery.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using Artskart3.Import.Core.Domain.Enums; | ||
|
|
||
| namespace Artskart3.Import.Core.Domain.Entities; | ||
|
|
||
| public class GbifDatasetDiscovery | ||
| { | ||
| public int Id { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The GBIF dataset key (UUID). | ||
| /// </summary> | ||
| public string GbifId { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// The GBIF publisher/organisation UUID. | ||
| /// </summary> | ||
| public Guid GbifPublisherId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The GBIF publishing organisation key string. | ||
| /// </summary> | ||
| public string PublishingOrganizationKey { get; set; } = string.Empty; | ||
|
|
||
| public string Title { get; set; } = string.Empty; | ||
|
|
||
| public string? Description { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The dataset homepage URL on GBIF. | ||
| /// </summary> | ||
| public string? HomepageUrl { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The Darwin Core Archive download URL. | ||
| /// </summary> | ||
| public string? DwcArchiveUrl { get; set; } | ||
|
|
||
| public string? Doi { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Additional identifiers for the dataset (stored as JSON array). | ||
| /// </summary> | ||
| public List<string> Identifiers { get; set; } = []; | ||
|
|
||
| /// <summary> | ||
| /// Review status of this discovered dataset. | ||
| /// </summary> | ||
| public DiscoveryStatus Status { get; set; } = DiscoveryStatus.Pending; | ||
|
|
||
| /// <summary> | ||
| /// When this dataset was first discovered via the GBIF API. | ||
| /// </summary> | ||
| public DateTime DiscoveredAt { get; set; } | ||
|
|
||
| public DateTime CreatedAt { get; set; } | ||
| public DateTime UpdatedAt { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| namespace Artskart3.Import.Core.Domain.Enums; | ||
|
|
||
| public enum DiscoveryStatus | ||
| { | ||
| /// <summary> | ||
| /// Discovered via the GBIF API but not yet reviewed. | ||
| /// </summary> | ||
| Pending, | ||
|
|
||
| /// <summary> | ||
| /// Reviewed and approved for import as a DataSource. | ||
| /// </summary> | ||
| Approved, | ||
|
|
||
| /// <summary> | ||
| /// Reviewed and determined to be not relevant for import. | ||
| /// </summary> | ||
| Rejected | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace Artskart3.Import.Core.Domain.Enums; | ||
|
|
||
| public enum ProviderType | ||
| { | ||
| ArtskartDataDeliveryWebServiceV1 = 0, | ||
| GbifIpt = 1, | ||
| Artsobservasjoner20Api = 2, | ||
| GbifApi = 3 | ||
| } |
12 changes: 12 additions & 0 deletions
12
Artskart3.Import.Core/Domain/RepositoryInterfaces/IDataSourceRepository.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using Artskart3.Import.Core.Domain.Entities; | ||
|
|
||
| namespace Artskart3.Import.Core.Domain.RepositoryInterfaces; | ||
|
|
||
| public interface IDataSourceRepository | ||
| { | ||
| Task<IEnumerable<DataSource>> GetAllAsync(CancellationToken cancellationToken = default); | ||
| Task<DataSource?> GetByIdAsync(int id, CancellationToken cancellationToken = default); | ||
| Task<DataSource> AddAsync(DataSource dataSource, CancellationToken cancellationToken = default); | ||
| Task UpdateAsync(DataSource dataSource, CancellationToken cancellationToken = default); | ||
| Task DeleteAsync(int id, CancellationToken cancellationToken = default); | ||
| } |
14 changes: 14 additions & 0 deletions
14
Artskart3.Import.Core/Domain/RepositoryInterfaces/IGbifDatasetDiscoveryRepository.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using Artskart3.Import.Core.Domain.Entities; | ||
| using Artskart3.Import.Core.Domain.Enums; | ||
|
|
||
| namespace Artskart3.Import.Core.Domain.RepositoryInterfaces; | ||
|
|
||
| public interface IGbifDatasetDiscoveryRepository | ||
| { | ||
| Task<IEnumerable<GbifDatasetDiscovery>> GetAllAsync(); | ||
| Task<IEnumerable<GbifDatasetDiscovery>> GetByStatusAsync(DiscoveryStatus status); | ||
| Task<GbifDatasetDiscovery?> GetByIdAsync(int id); | ||
| Task<GbifDatasetDiscovery?> GetByGbifIdAsync(string gbifId); | ||
| Task AddAsync(GbifDatasetDiscovery discovery); | ||
| Task UpdateAsync(GbifDatasetDiscovery discovery); | ||
| } |
29 changes: 29 additions & 0 deletions
29
Artskart3.Import.Infrastructure/Artskart3.Import.Infrastructure.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Artskart3.Import.Core\Artskart3.Import.Core.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.5" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.5"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.5" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.5"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0" /> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.0" /> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.5" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
28 changes: 28 additions & 0 deletions
28
Artskart3.Import.Infrastructure/Data/ArtskartImportDbContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using Artskart3.Import.Core.Domain.Entities; | ||
| using Artskart3.Import.Infrastructure.Data.EntityConfigurations; | ||
| using Microsoft.EntityFrameworkCore; | ||
|
|
||
| namespace Artskart3.Import.Infrastructure.Data; | ||
|
|
||
| public class ArtskartImportDbContext : DbContext | ||
| { | ||
| public ArtskartImportDbContext() | ||
| { | ||
| } | ||
|
|
||
| public ArtskartImportDbContext(DbContextOptions<ArtskartImportDbContext> options) | ||
| : base(options) | ||
| { | ||
| } | ||
|
|
||
| public virtual DbSet<DataSource> DataSources { get; set; } | ||
| public virtual DbSet<GbifDatasetDiscovery> GbifDatasetDiscoveries { get; set; } | ||
|
|
||
| protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
| { | ||
| modelBuilder.ApplyConfiguration(new DataSourceConfiguration()); | ||
| modelBuilder.ApplyConfiguration(new GbifDatasetDiscoveryConfiguration()); | ||
|
|
||
| base.OnModelCreating(modelBuilder); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
Artskart3.Import.Infrastructure/Data/ArtskartImportDbContextFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.EntityFrameworkCore.Design; | ||
| using Microsoft.Extensions.Configuration; | ||
|
|
||
| namespace Artskart3.Import.Infrastructure.Data; | ||
|
|
||
| /// <summary> | ||
| /// Used by EF Core tooling (dotnet ef migrations add, dotnet ef database update) at design time. | ||
| /// Reads the connection string from appsettings.json in the API project. | ||
| /// </summary> | ||
| public class ArtskartImportDbContextFactory : IDesignTimeDbContextFactory<ArtskartImportDbContext> | ||
| { | ||
| public ArtskartImportDbContext CreateDbContext(string[] args) | ||
| { | ||
| var configuration = new ConfigurationBuilder() | ||
| .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "..", "Artskart3.Api")) | ||
| .AddJsonFile("appsettings.json", optional: false) | ||
| .AddJsonFile("appsettings.Development.json", optional: true) | ||
| .Build(); | ||
|
|
||
| var connectionString = configuration.GetConnectionString("ArtskartImportDb") | ||
| ?? throw new InvalidOperationException("Connection string 'ArtskartImportDb' not found in appsettings.json."); | ||
|
|
||
| var optionsBuilder = new DbContextOptionsBuilder<ArtskartImportDbContext>(); | ||
| optionsBuilder.UseSqlServer(connectionString); | ||
|
|
||
| return new ArtskartImportDbContext(optionsBuilder.Options); | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
Artskart3.Import.Infrastructure/Data/EntityConfigurations/DataSourceConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using Artskart3.Import.Core.Domain.Entities; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
|
||
| namespace Artskart3.Import.Infrastructure.Data.EntityConfigurations; | ||
|
|
||
| public class DataSourceConfiguration : IEntityTypeConfiguration<DataSource> | ||
| { | ||
| public void Configure(EntityTypeBuilder<DataSource> builder) | ||
| { | ||
| builder.ToTable("DataSource"); | ||
|
|
||
| builder.HasKey(e => e.Id); | ||
|
|
||
| builder.Property(e => e.Name) | ||
| .IsRequired() | ||
| .HasMaxLength(500); | ||
|
|
||
| builder.Property(e => e.ProviderType) | ||
| .IsRequired(); | ||
|
|
||
| builder.Property(e => e.RemoteAddress) | ||
| .HasMaxLength(1000); | ||
|
|
||
| builder.Property(e => e.ArchiveName) | ||
| .HasMaxLength(500); | ||
|
|
||
| builder.Property(e => e.Notes) | ||
| .HasMaxLength(2000); | ||
|
|
||
| // Large JSON columns — no length limit | ||
| builder.Property(e => e.GbifApiQuery) | ||
| .HasColumnType("nvarchar(max)"); | ||
|
|
||
| builder.Property(e => e.HarvestPropertyOverrides) | ||
| .HasColumnType("nvarchar(max)"); | ||
|
|
||
| builder.Property(e => e.ImportPropertyOverrides) | ||
| .HasColumnType("nvarchar(max)"); | ||
|
|
||
| builder.Property(e => e.Doi) | ||
| .HasMaxLength(200); | ||
|
|
||
| builder.HasIndex(e => e.ProviderType) | ||
| .HasDatabaseName("IX_DataSource_ProviderType"); | ||
|
|
||
| builder.HasIndex(e => e.IsDeleted) | ||
| .HasDatabaseName("IX_DataSource_IsDeleted"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeg lurer litt på om det er nødvendig å ha egne prosjekt for dette? Ser at undermappene i disse nye Artskart3.Import prosjektene er helt like de som er under Core og Infrastructure allerede 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seperation of concerns. Det er helt eget prosjekt, men med samme undermapper ettersom at vi følger Clean Architecture prinsippene tenker jeg.