mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Syntax fixes (#5367)
* Declare return types on functions And a very few other type related minor fixes * Minor syntax fixes * Remove unnecessary escape chars in regexes * Remove unnecessary awaits * Replace deprecated req.connection with req.socket * Replace deprecated upload with uploadOne * Remove unnecessary eslint-disable-next-line comments * Comment empty functions / catch or finally clauses * Fix irregular whitespaces * Add missing returns (null) * Remove unreachable code * A few logical fixes * Remove / Handle non-null assertions which are certainly unnecessary (e.g. in tests)
This commit is contained in:
@@ -55,7 +55,7 @@ database
|
||||
logger.trace(`[${delta.toFixed(3)}ms] ${queryInfo.sql} [${queryInfo.bindings.join(', ')}]`);
|
||||
});
|
||||
|
||||
export async function hasDatabaseConnection() {
|
||||
export async function hasDatabaseConnection(): Promise<boolean> {
|
||||
try {
|
||||
if (env.DB_CLIENT === 'oracledb') {
|
||||
await database.raw('select 1 from DUAL');
|
||||
@@ -68,7 +68,7 @@ export async function hasDatabaseConnection() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function validateDBConnection() {
|
||||
export async function validateDBConnection(): Promise<void> {
|
||||
try {
|
||||
await hasDatabaseConnection();
|
||||
} catch (error) {
|
||||
@@ -80,7 +80,7 @@ export async function validateDBConnection() {
|
||||
|
||||
export const schemaInspector = SchemaInspector(database);
|
||||
|
||||
export async function isInstalled() {
|
||||
export async function isInstalled(): Promise<boolean> {
|
||||
// The existence of a directus_collections table alone isn't a "proper" check to see if everything
|
||||
// is installed correctly of course, but it's safe enough to assume that this collection only
|
||||
// exists when using the installer CLI.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_fields', (table) => {
|
||||
table.dropForeign(['collection']);
|
||||
});
|
||||
@@ -27,7 +27,7 @@ export async function up(knex: Knex) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_fields', (table) => {
|
||||
table.foreign('collection').references('directus_collections.collection');
|
||||
});
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Knex } from 'knex';
|
||||
import { merge } from 'lodash';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex('directus_relations')
|
||||
.delete()
|
||||
.where('many_collection', 'like', 'directus_%')
|
||||
.andWhere('one_collection', 'like', 'directus_%');
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
const defaults = {
|
||||
many_collection: 'directus_users',
|
||||
many_field: null,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Knex } from 'knex';
|
||||
import { merge } from 'lodash';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex('directus_collections').delete().where('collection', 'like', 'directus_%');
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
const defaults = {
|
||||
collection: null,
|
||||
hidden: false,
|
||||
|
||||
@@ -1639,12 +1639,12 @@ const systemFields = [
|
||||
return merge({}, defaults, row);
|
||||
});
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
const fieldKeys = uniq(systemFields.map((field: any) => field.field));
|
||||
|
||||
await knex('directus_fields').delete().where('collection', 'like', 'directus_%').whereIn('field', fieldKeys);
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.insert(systemFields).into('directus_fields');
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ const updates = [
|
||||
* Postgres behaves erratic on those triggers, not sure if MySQL / Maria plays nice either.
|
||||
*/
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
for (const update of updates) {
|
||||
await knex.schema.alterTable(update.table, (table) => {
|
||||
for (const constraint of update.constraints) {
|
||||
@@ -125,7 +125,7 @@ export async function up(knex: Knex) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
for (const update of updates) {
|
||||
await knex.schema.alterTable(update.table, (table) => {
|
||||
for (const constraint of update.constraints) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_webhooks', (table) => {
|
||||
table.text('url').alter();
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_webhooks', (table) => {
|
||||
table.string('url').alter();
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_relations', (table) => {
|
||||
table.string('sort_field');
|
||||
});
|
||||
@@ -26,7 +26,7 @@ export async function up(knex: Knex) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_relations', (table) => {
|
||||
table.dropColumn('sort_field');
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_fields', (table) => {
|
||||
table.dropColumn('locked');
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_fields', (table) => {
|
||||
table.boolean('locked').defaultTo(false).notNullable();
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_webhooks', (table) => {
|
||||
table.text('collections').alter();
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_webhooks', (table) => {
|
||||
table.string('collections').alter();
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_presets', (table) => {
|
||||
table.integer('refresh_interval');
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_presets', (table) => {
|
||||
table.dropColumn('refresh_interval');
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_files', (table) => {
|
||||
table.integer('filesize').nullable().defaultTo(null).alter();
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_files', (table) => {
|
||||
table.integer('filesize').notNullable().defaultTo(0).alter();
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_collections', (table) => {
|
||||
table.string('accountability').defaultTo('all');
|
||||
});
|
||||
@@ -8,7 +8,7 @@ export async function up(knex: Knex) {
|
||||
await knex('directus_collections').update({ accountability: 'all' });
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('directus_collections', (table) => {
|
||||
table.dropColumn('accountability');
|
||||
});
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex('directus_fields').update({ interface: 'many-to-many' }).where({ interface: 'files' });
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {}
|
||||
export async function down(_knex: Knex): Promise<void> {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ type Migration = {
|
||||
timestamp: Date;
|
||||
};
|
||||
|
||||
export default async function run(database: Knex, direction: 'up' | 'down' | 'latest') {
|
||||
export default async function run(database: Knex, direction: 'up' | 'down' | 'latest'): Promise<void> {
|
||||
let migrationFiles = await fse.readdir(__dirname);
|
||||
|
||||
const customMigrationsPath = path.resolve(env.EXTENSIONS_PATH, 'migrations');
|
||||
|
||||
@@ -25,7 +25,7 @@ type TableSeed = {
|
||||
};
|
||||
};
|
||||
|
||||
export default async function runSeed(database: Knex) {
|
||||
export default async function runSeed(database: Knex): Promise<void> {
|
||||
const exists = await database.schema.hasTable('directus_collections');
|
||||
|
||||
if (exists) {
|
||||
|
||||
Reference in New Issue
Block a user