Files
Automata/packages/cli/src/databases/utils.ts
Iván Ovejero f29950ee81 🐛 Fix executions pruning and UTC storage (#1959)
*  Add logging for pruning errors

*  Reformat pruning date to UTC string

*  Reformat workflow deletion date to UTC

*  Enforce UTC datetimes for MySQL

*  Enforce UTC datetimes for Postgres

*  Revert "Reformat workflow deletion date to UTC"

This reverts commit ca9628bc6d2b7d5786e45e8000086a3126b880ae.
2021-07-23 21:40:53 +02:00

43 lines
947 B
TypeScript

import {
DatabaseType,
} from '../index';
import { getConfigValueSync } from '../../src/GenericHelpers';
/**
* Resolves the data type for the used database type
*
* @export
* @param {string} dataType
* @returns {string}
*/
export function resolveDataType(dataType: string) {
const dbType = getConfigValueSync('database.type') as DatabaseType;
const typeMap: { [key in DatabaseType]: { [key: string]: string } } = {
sqlite: {
json: 'simple-json',
},
postgresdb: {
datetime: 'timestamptz',
},
mysqldb: {},
mariadb: {},
};
return typeMap[dbType][dataType] ?? dataType;
}
export function getTimestampSyntax() {
const dbType = getConfigValueSync('database.type') as DatabaseType;
const map: { [key in DatabaseType]: string } = {
sqlite: "STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')",
postgresdb: "CURRENT_TIMESTAMP(3)",
mysqldb: "CURRENT_TIMESTAMP(3)",
mariadb: "CURRENT_TIMESTAMP(3)",
};
return map[dbType];
}