Fix data type inconsistencies in directus_shares table (#10740)

* Fix date resolution in share info endpoint

* Add note on leaving fields blank

* Tweak example to use proper db client

* Treat mysql 0000-00-00 00:00:00 as null

* Fix migration for mysql 5

* Add missing defaults to system fields
This commit is contained in:
Rijk van Zanten
2021-12-28 18:32:27 -05:00
committed by GitHub
parent 8a0fba0691
commit a5f64efb22
7 changed files with 18 additions and 6 deletions

View File

@@ -139,7 +139,7 @@ router.get(
_or: [
{
date_start: {
_lte: '$NOW',
_lte: new Date().toISOString(),
},
},
{
@@ -153,7 +153,7 @@ router.get(
_or: [
{
date_end: {
_gte: '$NOW',
_gte: new Date().toISOString(),
},
},
{

View File

@@ -10,8 +10,11 @@ export async function up(knex: Knex): Promise<void> {
table.string('password');
table.uuid('user_created').references('id').inTable('directus_users').onDelete('SET NULL');
table.timestamp('date_created').defaultTo(knex.fn.now());
table.timestamp('date_start');
table.timestamp('date_end');
// This was changed after the migration went live to retroactively fix mysql5, see #10693
table.timestamp('date_start').nullable().defaultTo(null);
table.timestamp('date_end').nullable().defaultTo(null);
table.integer('times_used').defaultTo(0);
table.integer('max_uses');
});

View File

@@ -12,3 +12,5 @@ width: full
group: null
translations: null
note: null
conditions: null
required: false

View File

@@ -32,15 +32,19 @@ fields:
iconRight: lock
masked: true
width: half
note: $t:shared_leave_blank_for_unlimited
- field: date_start
width: half
note: $t:shared_leave_blank_for_unlimited
- field: date_end
width: half
note: $t:shared_leave_blank_for_unlimited
- field: max_uses
width: half
note: $t:shared_leave_blank_for_unlimited
- field: times_used
width: half

View File

@@ -14,7 +14,7 @@ export default function getDefaultValue(
if (defaultValue === 'null') return null;
if (defaultValue === 'NULL') return null;
// Check if the default is wrapped in an extra pair of quotes, this happens in SQLite
// Check if the default is wrapped in an extra pair of quotes, this happens in SQLite / MariaDB
if (
typeof defaultValue === 'string' &&
((defaultValue.startsWith(`'`) && defaultValue.endsWith(`'`)) ||
@@ -23,6 +23,8 @@ export default function getDefaultValue(
defaultValue = defaultValue.slice(1, -1);
}
if (defaultValue === '0000-00-00 00:00:00') return null;
switch (type) {
case 'bigInteger':
case 'integer':