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

[Mysql]: Added defaultCurrentTimestamp and onUpdateCurrentTimestamp to datetime #1114

Open
wants to merge 8 commits into
base: beta
Choose a base branch
from

Conversation

Angelelz
Copy link
Collaborator

The changes were made in date.common.ts due to the code that can be shared between timestamp and datetime data types in Mysql.

  • The method defaultNow() has been deprecated in favor of defaultCurrentTimestamp
  • The method onUpdateNow() has been deprecated in favor of onUpdateCurrentTimestamp
  • An additional fsp config parameter was added to MysqlDateColumnBaseConfig class. This will be helpful for Drizzle-kit to be able to add to correct fsp configuration to ON UPDATE. See here
  • No tests were added. The methods in this PR are only usable by drizzle-kit migration generation.

Users can now use the these methods in their schema definition as follows:

export const users = mysqlTable(
  "users",
  {
    id: char("id", { length: 26 }).primaryKey().notNull(),
    username: varchar("username", { length: 191 }).notNull(),
    createdAt: datetime("createdAt", { mode: "date", fsp: 3})
      .defaultCurrentTimestamp(),
    updatedAt: datetime("updatedAt", {mode: "date", fsp: 3})
      .defaultCurrentTimestamp()
      .onUpdateCurrentTimestamp(),
  },
);

This PR will close drizzle-team/drizzle-kit-mirror#596 and #921

Angelelz and others added 2 commits August 24, 2023 20:55
…o datetime

 - The method defaultNow() has been deprecated in favor of defaultCurrentTimestamp

 - The method onUpdateNow() has been deprecated in favor of onUpdateCurrentTimestamp
@statusunknown418
Copy link

this needs merging :(

@kasperaamodt
Copy link

When will this be released? And will the functions accept and FSP param?

@mauriciabad
Copy link

@Angelelz I guess this PR should be merged to beta branch instead of main.

@AndriiSherman can you check this out and ensure it is added to the next release? It seems almost finished. :D

@Angelelz
Copy link
Collaborator Author

This PR will probably also close #624.

@basemkhirat
Copy link

Need merge.

@statusunknown418
Copy link

any updates on merging this PR? looks really useful and checks on it are passing

@aretrace
Copy link

I was about to open an issue regarding this exact thing. This implementation reflects a widespread common declaration pattern when implementing timestamp fields. I would like to urge a merge at the earliest possible convenience.

@statusunknown418
Copy link

well all changes seem approved and checks are passing let's hope they merge it soon! @aretrace

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.

[FEATURE]: Add updateNow for datetime in MySQL
7 participants