Skip to content

fix: apply DateTime to DATE mapping#633

Open
sdahps wants to merge 2 commits intogoogleapis:mainfrom
sdahps:date-only-migrations
Open

fix: apply DateTime to DATE mapping#633
sdahps wants to merge 2 commits intogoogleapis:mainfrom
sdahps:date-only-migrations

Conversation

@sdahps
Copy link

@sdahps sdahps commented Dec 5, 2025

Fixes #632

Adds a mapping that works for DateTime and DATE, allowing migrations to be created again.

Note: this might be a naive approach, it's a large guess on my part but thought worth showing as the tests still pass.

  • Tests pass
  • Appropriate changes to README are included in PR

@gemini-code-assist
Copy link

Summary of Changes

Hello @sdahps, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where Entity Framework Core migrations failed when attempting to map .NET DateTime properties to Spanner's DATE columns. By introducing a dedicated type mapping and updating the mapping resolution logic, it ensures that DateTime values are correctly handled for DATE columns, thereby enabling successful migration creation and application. The author notes this might be a naive approach but confirms tests pass.

Highlights

  • New Type Mapping for DateTime to DATE: Introduced a new type mapping, SpannerDateDateTimeTypeMapping, specifically designed to handle the conversion of .NET DateTime objects to Spanner's DATE type.
  • Refactored SpannerDateTypeMapping: The SpannerDateTypeMapping class was refactored to include a protected constructor that accepts a CLR type, allowing for more flexible and conditional application of type converters based on the specific CLR type being mapped.
  • Updated Type Mapping Source Logic: The SpannerTypeMappingSource was updated to correctly identify and apply the new SpannerDateDateTimeTypeMapping when a .NET DateTime is intended to be mapped to a Spanner DATE column, resolving issues with migration generation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a fix to allow mapping the .NET DateTime type to the Spanner DATE type. The changes include a new SpannerDateDateTimeTypeMapping class, modifications to SpannerDateTypeMapping to support different CLR types, and updated logic in SpannerTypeMappingSource to select the correct mapping. The approach is sound and addresses the issue. I have one suggestion to improve a comment for clarity.

if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping)
|| _storeTypeMappings.TryGetValue(storeTypeNameBase, out mapping))
{
// if DateTime is being used to map to DATE we need to use the default DateTime<>DateTime mapping instead of trying to use DateTime<>SpannerDate

Choose a reason for hiding this comment

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

medium

This comment is a bit misleading. The mapping being returned is for DateTime to the store type DATE, not a DateTime<>DateTime mapping. This logic is special handling for when a DateTime property is explicitly configured to map to a DATE column. A clearer comment would help future maintainers understand this specific logic.

// When mapping DateTime to DATE, use a specific mapping for DateTime. The default DATE mapping is for SpannerDate and uses a converter.

@olavloite
Copy link
Collaborator

Hi @sdahps

Sorry for the slow response. Thanks for opening this PR. Would you mind giving a bit of background on exactly what it is that you would want to achieve with this? (And/or add some tests that show how this would be used?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrations: nullable DATE columns break migrations

2 participants