Giter Club home page Giter Club logo

Comments (1)

Hirevo avatar Hirevo commented on May 18, 2024

Good catch, I was indeed able to reproduce it.
I have done my tests of the mysql feature using mariadb instead of the actual mysql and I didn't encounter that issue.

It seems that MySQL does not support computed expressions as a default for columns:
https://stackoverflow.com/questions/360467/mysql-set-default-value-for-field-as-a-string-concatenation-function
The most immediate fix would be to remove these defaults and use triggers to set the values if not specified upon insert:

create table crates (
    id bigint not null auto_increment unique primary key,
    name varchar(255) not null unique,
    description varchar(4096),
    created_at varchar(25),
    updated_at varchar(25),
    downloads bigint not null default 0,
    documentation varchar(1024),
    repository varchar(1024)
);

delimiter //
create trigger default_crate_fields
before insert on crates
for each row
begin
  if (new.created_at is null) then
    set new.created_at = concat(utc_date(), ' ', utc_time());
  end if;
  if (new.updated_at is null) then
    set new.updated_at = new.created_at;
  end if;
end//
delimiter ;

Another route could be to just not use defaults nor triggers and just always specify these dates when inserting to the database.

I think the second option would be better because specifying the date is technically easy and would simplify the schema for every vendors.
Also, the first option makes the created_at and updated_at columns nullable.

So, I think I'll be pushing a PR for option 2.

from alexandrie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.