Skip to content

138 datasource entity ef migration - #166

Open
bolsson wants to merge 9 commits into
developfrom
138-datasource-entity-ef-migration
Open

138 datasource entity ef migration#166
bolsson wants to merge 9 commits into
developfrom
138-datasource-entity-ef-migration

Conversation

@bolsson

@bolsson bolsson commented Apr 30, 2026

Copy link
Copy Markdown
Contributor
  1. PR Description for 138-datasource-entity-ef-migration

Få oversikt over objekttyper i RavenDB #138 — DataSource entity and EF migration
Summary
As part of the RavenDB → SQL Server migration analysis for Artskart3, this PR introduces the DataSource entity which replaces the SourceDataBase document type from the old RavenDB store (Artskart2Core).
The design is based on a live data analysis of all 430 SourceDataBase documents across the four provider types found in production:
• 389 × GbifIpt
• 36 × ArtskartDataDeliveryWebServiceV1
• 4 × GbifApi
• 1 × Artsobservasjoner20Api
Changes
• ProviderType enum — clean replacement for RemoteDataSourceTypeEnum (dropped GbifJson which had zero live records)
• DataSource entity — flat table inheriting BaseEntity, with:
• Doi (string?) replacing GbifDataSetId — nullable in DB, enforced at the application layer for relevant provider types
• GbifApiQuery, HarvestPropertyOverrides, ImportPropertyOverrides — stored as nvarchar(max) (large JSON payloads)
• Property names cleaned up: RemoteAddress, ArchiveName, NonValidOccurrenceIds, WebServiceVersion
• GbifPublisherId kept as Guid? (nullable — only relevant for API-based providers)
• DataSourceConfiguration — EF fluent configuration with column constraints and indexes on ProviderType and IsDeleted
• EF migration AddDataSource — generates the DataSource table
• Fixed a pre-existing bug: OnModelCreatingPartial was declared but never called from OnModelCreating

Additional changes (extended scope)
Refactored import layer into Clean Architecture
The initial single Artskart3.Import project was split into two projects following the same Clean Architecture pattern as the rest of the solution:
• Artskart3.Import.Core — domain entities, enums, repository interfaces (no EF dependency)
• Artskart3.Import.Infrastructure — EF DbContext, migrations, repository implementations, DI wiring
GbifDatasetDiscovery entity
Replaces GbifDataSetInfo from RavenDB — a staging table for datasets discovered via the GBIF API. The NonRelevant bool has been replaced with a proper DiscoveryStatus enum (Pending, Approved, Rejected). A unique index on GbifId prevents duplicate discoveries.
Architecture decisions documented
• Three-database architecture agreed: Artskart3Import, Artskart3Cache, Artskart3Index
• Taxonomy sourced from Nortaxa API — not stored as owned data; taxon tree will be cached in Artskart3Index for UI performance
• README updated with database overview and EF migration commands for all contexts

Running locally
Ensure your Artskart3.Api/appsettings.json connection string points at your local SQL Server instance, then run:

Create/update the Artskart3Import database

dotnet ef database update --project Artskart3.Import.Infrastructure
--startup-project Artskart3.Api `
--context ArtskartImportDbContext

This will create the Artskart3Import database (if it doesn't exist) and apply both migrations:
• InitialImportBaseline — creates the DataSource table
• AddGbifDatasetDiscovery — creates the GbifDatasetDiscovery table

Out of scope / future work
• RawOccurrence entity in Artskart3Cache — SQL representation of a raw Darwin Core (DwC) occurrence record as received from providers (DwC-A archives, GBIF API). Largest migration item, warrants its own issue.
• Occurrence entity in Artskart3Index
• TaxonomyChangeLog (replacement for ArtskartEvent)
• Data migration tool from RavenDB → SQL

- Add ProviderType enum replacing RemoteDataSourceTypeEnum
- Add DataSource entity (flat table, inherits BaseEntity)
  - Doi replaces GbifDataSetId (nullable in DB, enforced at app layer)
  - Cleaned-up property names: RemoteAddress, ArchiveName,
    NonValidOccurrenceIds, WebServiceVersion
  - GbifApiQuery/HarvestPropertyOverrides/ImportPropertyOverrides
    stored as nvarchar(max) for large JSON payloads
- Add DataSourceConfiguration with column constraints and indexes
- Wire up OnModelCreatingPartial call in ArtskartDbContext
- Add EF migration AddDataSource
@bolsson bolsson self-assigned this Apr 30, 2026
@bolsson bolsson linked an issue Apr 30, 2026 that may be closed by this pull request
bolsson and others added 5 commits April 30, 2026 14:32
3-database architecture:
  DB1 Artskart3Import  - raw import data (this project)
  DB2 Artskart3Core    - processed/standardised observations (Artskart3.Infrastructure)
  DB3 Artskart3Index   - search-optimised index (future index3core)

Changes:
- Remove DataSource entity and ProviderType enum from Artskart3.Core
- Revert Artskart3.Infrastructure to pre-DataSource state (migration,
  DbSet, EntityConfiguration and OnModelCreatingPartial call removed,
  model snapshot restored)
- Create Artskart3.Import class library (net10.0, EF Core 10.0.5)
- Add DataSource entity, ProviderType enum, DataSourceConfiguration,
  ArtskartImportDbContext and ArtskartImportDbContextFactory
- Add InitialImportBaseline EF migration for Artskart3Import database
- Add Artskart3.Import to solution and as reference in Artskart3.Api
- Add ArtskartImportDb connection string to appsettings.json
<ItemGroup>
<ProjectReference Include="..\Artskart3.Core\Artskart3.Core.csproj" />
<ProjectReference Include="..\Artskart3.Infrastructure\Artskart3.Infrastructure.csproj" />
<ProjectReference Include="..\Artskart3.Import.Infrastructure\Artskart3.Import.Infrastructure.csproj" />

Copy link
Copy Markdown
Contributor

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 🤔

Copy link
Copy Markdown
Contributor Author

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.

Comment thread Artskart3.Import.Core/Domain/Entities/DataSource.cs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hva er det denne configuration fila gjør egentlig?

bolsson and others added 3 commits May 13, 2026 12:00
…ity-ef-migration

# Conflicts:
#	Artskart3.Api/appsettings.json
#	Artskart3.slnx
Updated summary comment for DataSource class to remove reference to SourceDataBase in RavenDB.

Signed-off-by: bolsson <6236608+bolsson@users.noreply.github.com>
@Kristoffer-Martinsen Kristoffer-Martinsen added the on-hold Put on hold on purpose by the team. label May 21, 2026
@bolsson bolsson linked an issue May 22, 2026 that may be closed by this pull request
30 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on-hold Put on hold on purpose by the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementere Core (Artskart3Core) databasen i SQL

4 participants