cnpmcore icon indicating copy to clipboard operation
cnpmcore copied to clipboard

package_version_files 表 datetime 缺少默认值

Open Beace opened this issue 2 years ago • 3 comments

sql 需要加个默认值,不然跑起来会报错

sql: "INSERT INTO `package_version_files` (`package_version_file_id`, `package_version_id`, `directory`, `name`, `content_type`, `dist_id`, `mtime`) VALUES ('64772de4c4fcb3e700424fdf', '641bd11a5ccb5d0ca71a2df3', '/', 'license', 'text/plain', '64772de4c4fcb3e700424fde', '2023-03-17 14:07:40.000')"
}
nodejs.ER_NO_DEFAULT_FOR_FIELDError: ER_NO_DEFAULT_FOR_FIELD: Field 'gmt_create' doesn't have a default value

如下

CREATE TABLE IF NOT EXISTS `package_version_files` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
  `gmt_create` datetime(3) **DEFAULT CURRENT_TIMESTAMP(3)** NOT NULL COMMENT 'create time',
  `gmt_modified` datetime(3) **DEFAULT CURRENT_TIMESTAMP(3)** NOT NULL COMMENT 'modified time',
  `package_version_id` varchar(24) NOT NULL COMMENT 'package version id',
  `package_version_file_id` varchar(24) NOT NULL COMMENT 'package version file id',
  `dist_id` varchar(24) NOT NULL COMMENT 'file dist id',
  `directory` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'directory path, e.g.: /bin',
  `name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'file name, e.g.: index.js',
  `content_type` varchar(200) NOT NULL COMMENT 'file content type, e.g.: application/javascript',
  `mtime` datetime(3) NOT NULL COMMENT 'file modified time',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_package_version_file_id` (`package_version_file_id`),
  UNIQUE KEY `ux_package_version_id_directory_name` (`package_version_id`, `directory`, `name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='package version file';

Beace avatar May 31 '23 11:05 Beace

怎么重现的?

fengmk2 avatar May 31 '23 13:05 fengmk2

Entity 在创建的时候会自动设置 createdAt 的 https://github.com/cnpm/cnpmcore/blob/master/app/core/util/EntityUtil.ts#L26

fengmk2 avatar May 31 '23 13:05 fengmk2

现在复现不了了,就初始化项目,建表,然后我往本地nfs publish 下,再请求下 unpkg 的 GET,就第一次这样。

Beace avatar Jun 01 '23 13:06 Beace