Skip to content
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

Implement CURRENT_TIMESTAMP support for datetime #959

Merged
merged 1 commit into from
Nov 24, 2019

Conversation

lauxjpn
Copy link
Collaborator

@lauxjpn lauxjpn commented Nov 21, 2019

We did already implement this for timestamp columns.

For the following table:

CREATE TABLE IF NOT EXISTS `modTest`(
  `id` INT NOT NULL AUTO_INCREMENT,
  `modify_date1` DATETIME NULL,
  `modify_date2` DATETIME NOT NULL,
  `modify_date3` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `modify_date4` DATETIME NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

The following model and definition is now being scaffolded:

public partial class ModTest
{
    public int Id { get; set; }
    public DateTime? ModifyDate1 { get; set; }
    public DateTime ModifyDate2 { get; set; }
    public DateTime ModifyDate3 { get; set; }
    public DateTime? ModifyDate4 { get; set; }
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<ModTest>(entity =>
    {
        entity.ToTable("modTest");

        entity.Property(e => e.Id)
            .HasColumnName("id")
            .HasColumnType("int(11)");

        entity.Property(e => e.ModifyDate1)
            .HasColumnName("modify_date1")
            .HasColumnType("datetime");

        entity.Property(e => e.ModifyDate2)
            .HasColumnName("modify_date2")
            .HasColumnType("datetime");

        entity.Property(e => e.ModifyDate3)
            .HasColumnName("modify_date3")
            .HasColumnType("datetime")
            .HasDefaultValueSql("CURRENT_TIMESTAMP");

        entity.Property(e => e.ModifyDate4)
            .HasColumnName("modify_date4")
            .HasColumnType("datetime")
            .ValueGeneratedOnAddOrUpdate();
    });

    OnModelCreatingPartial(modelBuilder);
}

Fixes #958

…rounds for EF Core `3.0.0`) as we previously did for `timestamp`.
@lauxjpn lauxjpn added this to the 3.1.0 milestone Nov 21, 2019
@lauxjpn lauxjpn self-assigned this Nov 21, 2019
@lauxjpn lauxjpn modified the milestones: 3.1.0, 3.0.1 Nov 21, 2019
@lauxjpn lauxjpn changed the title Implement CURRENT_TIMESTAMP support for datetime Implement CURRENT_TIMESTAMP support for datetime Nov 22, 2019
@lauxjpn lauxjpn merged commit f804faa into PomeloFoundation:master Nov 24, 2019
@lauxjpn lauxjpn deleted the fix/issue958 branch November 24, 2019 16:07
lauxjpn added a commit to lauxjpn/Pomelo.EntityFrameworkCore.MySql that referenced this pull request Nov 24, 2019
…rounds for EF Core `3.0.0`) as we previously did for `timestamp`. (PomeloFoundation#959)

(cherry picked from commit f804faa)
lauxjpn added a commit that referenced this pull request Nov 25, 2019
* Sort columns in order of their ordinal position to ensure the order of generated properties to be equal to the order of the table columns. (#951)

(cherry picked from commit 8cba627)

* Reinstate the `SetupMySqlOptions()` implementation and call it when scaffolding. (#955)

(cherry picked from commit a65a3ce)

* Correctly handle bit default values that use the `b'01'` syntax. (#956)

(cherry picked from commit f9c67dc)

* Implement CURRENT`_TIMESTAMP` support for `datetime` (including workarounds for EF Core `3.0.0`) as we previously did for `timestamp`. (#959)

(cherry picked from commit f804faa)

* Scaffold actual server version of the underlying database. (#961)

(cherry picked from commit bd64acc)

* Make `Pomelo.EntityFrameworkCore.MySql` strongly named. (#963)

(cherry picked from commit 9f2ce62)

* Fix troublesome test class for strong named scenarios. This is now needed again, because we did rely on an ordering xUnit extension library, that is not strong named and therefore had to be dropped. (#967)

(cherry picked from commit a2b6b59)

* Add missing store type mappings (#968)

Add supported type names: `integer` and `numeric`. Add supported unsigned types. The floating point variants are deprecated since 8.0.17-mysql.

(cherry picked from commit 2e7187b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with scaffolding a column with DATETIME NULL ON UPDATE CURRENT_TIMESTAMP
1 participant