directus 9.14.3 → 9.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +1 -1
- package/dist/auth/drivers/ldap.js +18 -8
- package/dist/auth/drivers/oauth2.js +19 -9
- package/dist/auth/drivers/openid.js +19 -9
- package/dist/cache.d.ts +3 -0
- package/dist/cache.js +21 -2
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -1
- package/dist/controllers/assets.js +23 -1
- package/dist/controllers/extensions.js +3 -2
- package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +3 -14
- package/dist/database/helpers/schema/dialects/cockroachdb.js +2 -8
- package/dist/database/helpers/schema/dialects/oracle.d.ts +3 -10
- package/dist/database/helpers/schema/dialects/oracle.js +2 -5
- package/dist/database/helpers/schema/types.d.ts +8 -18
- package/dist/database/helpers/schema/types.js +7 -36
- package/dist/database/migrations/20201105B-change-webhook-url-type.js +3 -2
- package/dist/database/migrations/20210312A-webhooks-collections-text.js +3 -2
- package/dist/database/migrations/20210415A-make-filesize-nullable.js +2 -2
- package/dist/database/migrations/20210510A-restructure-relations.js +3 -3
- package/dist/database/migrations/20210903A-add-auth-provider.js +2 -2
- package/dist/database/migrations/20210907A-webhooks-collections-not-null.js +4 -2
- package/dist/database/migrations/20210920A-webhooks-url-not-null.js +2 -2
- package/dist/database/migrations/20220303A-remove-default-project-color.js +2 -2
- package/dist/database/migrations/20220325B-add-default-language.js +2 -2
- package/dist/database/migrations/20220402A-remove-default-value-panel-icon.js +2 -2
- package/dist/database/migrations/20220801A-update-notifications-timestamp-column.d.ts +3 -0
- package/dist/database/migrations/20220801A-update-notifications-timestamp-column.js +19 -0
- package/dist/database/migrations/20220802A-add-custom-aspect-ratios.d.ts +3 -0
- package/dist/database/migrations/20220802A-add-custom-aspect-ratios.js +15 -0
- package/dist/database/system-data/fields/settings.yaml +33 -0
- package/dist/extensions.d.ts +2 -2
- package/dist/extensions.js +10 -9
- package/dist/logger.js +0 -1
- package/dist/middleware/cache.js +3 -3
- package/dist/middleware/respond.js +2 -2
- package/dist/operations/item-create/index.js +1 -1
- package/dist/operations/item-delete/index.js +2 -2
- package/dist/operations/item-read/index.js +2 -2
- package/dist/operations/item-update/index.js +3 -3
- package/dist/services/assets.d.ts +1 -1
- package/dist/services/assets.js +7 -2
- package/dist/services/authorization.js +2 -1
- package/dist/services/graphql/index.js +37 -11
- package/dist/services/graphql/types/hash.d.ts +2 -0
- package/dist/services/graphql/types/hash.js +9 -0
- package/dist/services/specifications.js +1 -6
- package/dist/utils/apply-query.js +11 -0
- package/dist/utils/compress.d.ts +3 -0
- package/dist/utils/compress.js +17 -0
- package/dist/utils/get-ast-from-query.js +1 -1
- package/dist/utils/get-graphql-type.js +3 -0
- package/dist/utils/get-permissions.js +2 -2
- package/dist/utils/get-schema.js +1 -2
- package/package.json +10 -9
package/dist/app.js
CHANGED
|
@@ -168,7 +168,7 @@ async function createApp() {
|
|
|
168
168
|
res.send(constants_1.ROBOTSTXT);
|
|
169
169
|
});
|
|
170
170
|
if (env_1.default.SERVE_APP) {
|
|
171
|
-
const adminPath = require.resolve('@directus/app');
|
|
171
|
+
const adminPath = require.resolve('@directus/app', require.main ? { paths: [require.main.filename] } : undefined);
|
|
172
172
|
const adminUrl = new url_1.Url(env_1.default.PUBLIC_URL).addPath('admin');
|
|
173
173
|
// Set the App's base path according to the APIs public URL
|
|
174
174
|
const html = await fs_extra_1.default.readFile(adminPath, 'utf8');
|
|
@@ -34,6 +34,7 @@ const get_ip_from_req_1 = require("../../utils/get-ip-from-req");
|
|
|
34
34
|
const joi_1 = __importDefault(require("joi"));
|
|
35
35
|
const auth_1 = require("../auth");
|
|
36
36
|
const exceptions_1 = require("../../exceptions");
|
|
37
|
+
const record_not_unique_1 = require("../../exceptions/database/record-not-unique");
|
|
37
38
|
const services_1 = require("../../services");
|
|
38
39
|
const async_handler_1 = __importDefault(require("../../utils/async-handler"));
|
|
39
40
|
const env_1 = __importDefault(require("../../env"));
|
|
@@ -218,14 +219,23 @@ class LDAPAuthDriver extends auth_1.AuthDriver {
|
|
|
218
219
|
if (!userInfo) {
|
|
219
220
|
throw new exceptions_1.InvalidCredentialsException();
|
|
220
221
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
222
|
+
try {
|
|
223
|
+
await this.usersService.createOne({
|
|
224
|
+
provider: this.config.provider,
|
|
225
|
+
first_name: userInfo.firstName,
|
|
226
|
+
last_name: userInfo.lastName,
|
|
227
|
+
email: userInfo.email,
|
|
228
|
+
external_identifier: userInfo.dn,
|
|
229
|
+
role: (_c = userRole === null || userRole === void 0 ? void 0 : userRole.id) !== null && _c !== void 0 ? _c : defaultRoleId,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
catch (e) {
|
|
233
|
+
if (e instanceof record_not_unique_1.RecordNotUniqueException) {
|
|
234
|
+
logger_1.default.warn(e, '[LDAP] Failed to register user. User not unique');
|
|
235
|
+
throw new exceptions_1.InvalidProviderException();
|
|
236
|
+
}
|
|
237
|
+
throw e;
|
|
238
|
+
}
|
|
229
239
|
return (await this.fetchUserId(userInfo.dn));
|
|
230
240
|
}
|
|
231
241
|
async verify(user, password) {
|
|
@@ -14,6 +14,7 @@ const openid_client_1 = require("openid-client");
|
|
|
14
14
|
const auth_1 = require("../../auth");
|
|
15
15
|
const env_1 = __importDefault(require("../../env"));
|
|
16
16
|
const exceptions_2 = require("../../exceptions");
|
|
17
|
+
const record_not_unique_1 = require("../../exceptions/database/record-not-unique");
|
|
17
18
|
const logger_1 = __importDefault(require("../../logger"));
|
|
18
19
|
const respond_1 = require("../../middleware/respond");
|
|
19
20
|
const services_1 = require("../../services");
|
|
@@ -118,15 +119,24 @@ class OAuth2AuthDriver extends local_1.LocalAuthDriver {
|
|
|
118
119
|
logger_1.default.trace(`[OAuth2] User doesn't exist, and public registration not allowed for provider "${provider}"`);
|
|
119
120
|
throw new exceptions_2.InvalidCredentialsException();
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
122
|
+
try {
|
|
123
|
+
await this.usersService.createOne({
|
|
124
|
+
provider,
|
|
125
|
+
first_name: userInfo[this.config.firstNameKey],
|
|
126
|
+
last_name: userInfo[this.config.lastNameKey],
|
|
127
|
+
email: email,
|
|
128
|
+
external_identifier: identifier,
|
|
129
|
+
role: this.config.defaultRoleId,
|
|
130
|
+
auth_data: tokenSet.refresh_token && JSON.stringify({ refreshToken: tokenSet.refresh_token }),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
if (e instanceof record_not_unique_1.RecordNotUniqueException) {
|
|
135
|
+
logger_1.default.warn(e, '[OAuth2] Failed to register user. User not unique');
|
|
136
|
+
throw new exceptions_2.InvalidProviderException();
|
|
137
|
+
}
|
|
138
|
+
throw e;
|
|
139
|
+
}
|
|
130
140
|
return (await this.fetchUserId(identifier));
|
|
131
141
|
}
|
|
132
142
|
async login(user) {
|
|
@@ -14,6 +14,7 @@ const openid_client_1 = require("openid-client");
|
|
|
14
14
|
const auth_1 = require("../../auth");
|
|
15
15
|
const env_1 = __importDefault(require("../../env"));
|
|
16
16
|
const exceptions_2 = require("../../exceptions");
|
|
17
|
+
const record_not_unique_1 = require("../../exceptions/database/record-not-unique");
|
|
17
18
|
const logger_1 = __importDefault(require("../../logger"));
|
|
18
19
|
const respond_1 = require("../../middleware/respond");
|
|
19
20
|
const services_1 = require("../../services");
|
|
@@ -136,15 +137,24 @@ class OpenIDAuthDriver extends local_1.LocalAuthDriver {
|
|
|
136
137
|
logger_1.default.trace(`[OpenID] User doesn't exist, and public registration not allowed for provider "${provider}"`);
|
|
137
138
|
throw new exceptions_2.InvalidCredentialsException();
|
|
138
139
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
try {
|
|
141
|
+
await this.usersService.createOne({
|
|
142
|
+
provider,
|
|
143
|
+
first_name: userInfo.given_name,
|
|
144
|
+
last_name: userInfo.family_name,
|
|
145
|
+
email: email,
|
|
146
|
+
external_identifier: identifier,
|
|
147
|
+
role: this.config.defaultRoleId,
|
|
148
|
+
auth_data: tokenSet.refresh_token && JSON.stringify({ refreshToken: tokenSet.refresh_token }),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
if (e instanceof record_not_unique_1.RecordNotUniqueException) {
|
|
153
|
+
logger_1.default.warn(e, '[OpenID] Failed to register user. User not unique');
|
|
154
|
+
throw new exceptions_2.InvalidProviderException();
|
|
155
|
+
}
|
|
156
|
+
throw e;
|
|
157
|
+
}
|
|
148
158
|
return (await this.fetchUserId(identifier));
|
|
149
159
|
}
|
|
150
160
|
async login(user) {
|
package/dist/cache.d.ts
CHANGED
|
@@ -7,3 +7,6 @@ export declare function getCache(): {
|
|
|
7
7
|
export declare function flushCaches(forced?: boolean): Promise<void>;
|
|
8
8
|
export declare function clearSystemCache(forced?: boolean): Promise<void>;
|
|
9
9
|
export declare function setSystemCache(key: string, value: any, ttl?: number): Promise<void>;
|
|
10
|
+
export declare function getSystemCache(key: string): Promise<Record<string, any>>;
|
|
11
|
+
export declare function setCacheValue(cache: Keyv, key: string, value: Record<string, any> | Record<string, any>[], ttl?: number): Promise<void>;
|
|
12
|
+
export declare function getCacheValue(cache: Keyv, key: string): Promise<any>;
|
package/dist/cache.js
CHANGED
|
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setSystemCache = exports.clearSystemCache = exports.flushCaches = exports.getCache = void 0;
|
|
6
|
+
exports.getCacheValue = exports.setCacheValue = exports.getSystemCache = exports.setSystemCache = exports.clearSystemCache = exports.flushCaches = exports.getCache = void 0;
|
|
7
7
|
const keyv_1 = __importDefault(require("keyv"));
|
|
8
8
|
const ms_1 = __importDefault(require("ms"));
|
|
9
9
|
const env_1 = __importDefault(require("./env"));
|
|
10
10
|
const logger_1 = __importDefault(require("./logger"));
|
|
11
11
|
const get_config_from_env_1 = require("./utils/get-config-from-env");
|
|
12
12
|
const validate_env_1 = require("./utils/validate-env");
|
|
13
|
+
const compress_1 = require("./utils/compress");
|
|
13
14
|
let cache = null;
|
|
14
15
|
let systemCache = null;
|
|
15
16
|
let lockCache = null;
|
|
@@ -49,10 +50,28 @@ exports.clearSystemCache = clearSystemCache;
|
|
|
49
50
|
async function setSystemCache(key, value, ttl) {
|
|
50
51
|
const { systemCache, lockCache } = getCache();
|
|
51
52
|
if (!(await lockCache.get('system-cache-lock'))) {
|
|
52
|
-
await systemCache
|
|
53
|
+
await setCacheValue(systemCache, key, value, ttl);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
exports.setSystemCache = setSystemCache;
|
|
57
|
+
async function getSystemCache(key) {
|
|
58
|
+
const { systemCache } = getCache();
|
|
59
|
+
return await getCacheValue(systemCache, key);
|
|
60
|
+
}
|
|
61
|
+
exports.getSystemCache = getSystemCache;
|
|
62
|
+
async function setCacheValue(cache, key, value, ttl) {
|
|
63
|
+
const compressed = await (0, compress_1.compress)(value);
|
|
64
|
+
await cache.set(key, compressed, ttl);
|
|
65
|
+
}
|
|
66
|
+
exports.setCacheValue = setCacheValue;
|
|
67
|
+
async function getCacheValue(cache, key) {
|
|
68
|
+
const value = await cache.get(key);
|
|
69
|
+
if (!value)
|
|
70
|
+
return undefined;
|
|
71
|
+
const decompressed = await (0, compress_1.decompress)(value);
|
|
72
|
+
return decompressed;
|
|
73
|
+
}
|
|
74
|
+
exports.getCacheValue = getCacheValue;
|
|
56
75
|
function getKeyvInstance(ttl, namespaceSuffix) {
|
|
57
76
|
switch (env_1.default.CACHE_STORE) {
|
|
58
77
|
case 'redis':
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const FILTER_VARIABLES: string[];
|
|
|
5
5
|
export declare const ALIAS_TYPES: string[];
|
|
6
6
|
export declare const DEFAULT_AUTH_PROVIDER = "default";
|
|
7
7
|
export declare const COLUMN_TRANSFORMS: string[];
|
|
8
|
+
export declare const GENERATE_SPECIAL: string[];
|
|
8
9
|
export declare const UUID_REGEX = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
9
10
|
export declare const COOKIE_OPTIONS: {
|
|
10
11
|
httpOnly: boolean;
|
package/dist/constants.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
var _a;
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ROBOTSTXT = exports.COOKIE_OPTIONS = exports.UUID_REGEX = exports.COLUMN_TRANSFORMS = exports.DEFAULT_AUTH_PROVIDER = exports.ALIAS_TYPES = exports.FILTER_VARIABLES = exports.ASSET_TRANSFORM_QUERY_KEYS = exports.SYSTEM_ASSET_ALLOW_LIST = void 0;
|
|
7
|
+
exports.ROBOTSTXT = exports.COOKIE_OPTIONS = exports.UUID_REGEX = exports.GENERATE_SPECIAL = exports.COLUMN_TRANSFORMS = exports.DEFAULT_AUTH_PROVIDER = exports.ALIAS_TYPES = exports.FILTER_VARIABLES = exports.ASSET_TRANSFORM_QUERY_KEYS = exports.SYSTEM_ASSET_ALLOW_LIST = void 0;
|
|
8
8
|
const env_1 = __importDefault(require("./env"));
|
|
9
9
|
const ms_1 = __importDefault(require("ms"));
|
|
10
10
|
exports.SYSTEM_ASSET_ALLOW_LIST = [
|
|
@@ -47,6 +47,7 @@ exports.FILTER_VARIABLES = ['$NOW', '$CURRENT_USER', '$CURRENT_ROLE'];
|
|
|
47
47
|
exports.ALIAS_TYPES = ['alias', 'o2m', 'm2m', 'm2a', 'o2a', 'files', 'translations'];
|
|
48
48
|
exports.DEFAULT_AUTH_PROVIDER = 'default';
|
|
49
49
|
exports.COLUMN_TRANSFORMS = ['year', 'month', 'day', 'weekday', 'hour', 'minute', 'second'];
|
|
50
|
+
exports.GENERATE_SPECIAL = ['uuid', 'date-created', 'role-created', 'user-created'];
|
|
50
51
|
exports.UUID_REGEX = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
|
|
51
52
|
exports.COOKIE_OPTIONS = {
|
|
52
53
|
httpOnly: true,
|
|
@@ -12,6 +12,7 @@ const constants_1 = require("../constants");
|
|
|
12
12
|
const database_1 = __importDefault(require("../database"));
|
|
13
13
|
const env_1 = __importDefault(require("../env"));
|
|
14
14
|
const exceptions_1 = require("../exceptions");
|
|
15
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
15
16
|
const use_collection_1 = __importDefault(require("../middleware/use-collection"));
|
|
16
17
|
const services_1 = require("../services");
|
|
17
18
|
const assets_1 = require("../types/assets");
|
|
@@ -147,6 +148,27 @@ router.get('/:pk/:filename?',
|
|
|
147
148
|
res.setHeader('Content-Length', stat.size);
|
|
148
149
|
return res.end();
|
|
149
150
|
}
|
|
150
|
-
stream.
|
|
151
|
+
stream.on('data', (chunk) => res.write(chunk));
|
|
152
|
+
stream.on('end', () => {
|
|
153
|
+
res.status(200).send();
|
|
154
|
+
});
|
|
155
|
+
stream.on('error', (e) => {
|
|
156
|
+
logger_1.default.error(e, `Couldn't stream file ${file.id} to the client`);
|
|
157
|
+
stream.unpipe(res);
|
|
158
|
+
res.removeHeader('Content-Disposition');
|
|
159
|
+
res.removeHeader('Content-Type');
|
|
160
|
+
res.removeHeader('Content-Disposition');
|
|
161
|
+
res.removeHeader('Cache-Control');
|
|
162
|
+
res.status(500).json({
|
|
163
|
+
errors: [
|
|
164
|
+
{
|
|
165
|
+
message: 'An unexpected error occurred.',
|
|
166
|
+
extensions: {
|
|
167
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
});
|
|
151
173
|
}));
|
|
152
174
|
exports.default = router;
|
|
@@ -9,13 +9,14 @@ const exceptions_1 = require("../exceptions");
|
|
|
9
9
|
const extensions_1 = require("../extensions");
|
|
10
10
|
const respond_1 = require("../middleware/respond");
|
|
11
11
|
const utils_1 = require("@directus/shared/utils");
|
|
12
|
+
const constants_1 = require("@directus/shared/constants");
|
|
12
13
|
const ms_1 = __importDefault(require("ms"));
|
|
13
14
|
const env_1 = __importDefault(require("../env"));
|
|
14
15
|
const get_cache_headers_1 = require("../utils/get-cache-headers");
|
|
15
16
|
const router = (0, express_1.Router)();
|
|
16
17
|
router.get('/:type', (0, async_handler_1.default)(async (req, res, next) => {
|
|
17
18
|
const type = (0, utils_1.depluralize)(req.params.type);
|
|
18
|
-
if (!(0, utils_1.
|
|
19
|
+
if (!(0, utils_1.isIn)(type, constants_1.APP_OR_HYBRID_EXTENSION_TYPES)) {
|
|
19
20
|
throw new exceptions_1.RouteNotFoundException(req.path);
|
|
20
21
|
}
|
|
21
22
|
const extensionManager = (0, extensions_1.getExtensionManager)();
|
|
@@ -27,7 +28,7 @@ router.get('/:type', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
27
28
|
}), respond_1.respond);
|
|
28
29
|
router.get('/:type/index.js', (0, async_handler_1.default)(async (req, res) => {
|
|
29
30
|
const type = (0, utils_1.depluralize)(req.params.type);
|
|
30
|
-
if (!(0, utils_1.
|
|
31
|
+
if (!(0, utils_1.isIn)(type, constants_1.APP_OR_HYBRID_EXTENSION_TYPES)) {
|
|
31
32
|
throw new exceptions_1.RouteNotFoundException(req.path);
|
|
32
33
|
}
|
|
33
34
|
const extensionManager = (0, extensions_1.getExtensionManager)();
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KNEX_TYPES } from '@directus/shared/constants';
|
|
2
|
+
import { Options, SchemaHelper } from '../types';
|
|
2
3
|
export declare class SchemaHelperCockroachDb extends SchemaHelper {
|
|
3
|
-
|
|
4
|
-
nullable?: boolean;
|
|
5
|
-
default?: any;
|
|
6
|
-
}): Promise<void>;
|
|
7
|
-
changeToString(table: string, column: string, options?: {
|
|
8
|
-
nullable?: boolean;
|
|
9
|
-
default?: any;
|
|
10
|
-
length?: number;
|
|
11
|
-
}): Promise<void>;
|
|
12
|
-
changeToInteger(table: string, column: string, options?: {
|
|
13
|
-
nullable?: boolean;
|
|
14
|
-
default?: any;
|
|
15
|
-
}): Promise<void>;
|
|
4
|
+
changeToType(table: string, column: string, type: typeof KNEX_TYPES[number], options?: Options): Promise<void>;
|
|
16
5
|
}
|
|
@@ -3,14 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SchemaHelperCockroachDb = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
class SchemaHelperCockroachDb extends types_1.SchemaHelper {
|
|
6
|
-
async
|
|
7
|
-
await this.changeToTypeByCopy(table, column,
|
|
8
|
-
}
|
|
9
|
-
async changeToString(table, column, options = {}) {
|
|
10
|
-
await this.changeToTypeByCopy(table, column, options, (builder, column, options) => builder.string(column, options.length));
|
|
11
|
-
}
|
|
12
|
-
async changeToInteger(table, column, options = {}) {
|
|
13
|
-
await this.changeToTypeByCopy(table, column, options, (builder, column) => builder.integer(column));
|
|
6
|
+
async changeToType(table, column, type, options = {}) {
|
|
7
|
+
await this.changeToTypeByCopy(table, column, type, options);
|
|
14
8
|
}
|
|
15
9
|
}
|
|
16
10
|
exports.SchemaHelperCockroachDb = SchemaHelperCockroachDb;
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KNEX_TYPES } from '@directus/shared/constants';
|
|
2
|
+
import { Options, SchemaHelper } from '../types';
|
|
2
3
|
export declare class SchemaHelperOracle extends SchemaHelper {
|
|
3
|
-
|
|
4
|
-
nullable?: boolean;
|
|
5
|
-
default?: any;
|
|
6
|
-
}): Promise<void>;
|
|
7
|
-
changeToString(table: string, column: string, options?: {
|
|
8
|
-
nullable?: boolean;
|
|
9
|
-
default?: any;
|
|
10
|
-
length?: number;
|
|
11
|
-
}): Promise<void>;
|
|
4
|
+
changeToType(table: string, column: string, type: typeof KNEX_TYPES[number], options?: Options): Promise<void>;
|
|
12
5
|
}
|
|
@@ -3,11 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SchemaHelperOracle = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
class SchemaHelperOracle extends types_1.SchemaHelper {
|
|
6
|
-
async
|
|
7
|
-
await this.changeToTypeByCopy(table, column,
|
|
8
|
-
}
|
|
9
|
-
async changeToString(table, column, options = {}) {
|
|
10
|
-
await this.changeToTypeByCopy(table, column, options, (builder, column, options) => builder.string(column, options.length));
|
|
6
|
+
async changeToType(table, column, type, options = {}) {
|
|
7
|
+
await this.changeToTypeByCopy(table, column, type, options);
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
10
|
exports.SchemaHelperOracle = SchemaHelperOracle;
|
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
import { DatabaseHelper } from '../types';
|
|
2
|
-
import {
|
|
2
|
+
import { KNEX_TYPES } from '@directus/shared/constants';
|
|
3
3
|
declare type Clients = 'mysql' | 'postgres' | 'cockroachdb' | 'sqlite' | 'oracle' | 'mssql' | 'redshift';
|
|
4
|
+
export declare type Options = {
|
|
5
|
+
nullable?: boolean;
|
|
6
|
+
default?: any;
|
|
7
|
+
length?: number;
|
|
8
|
+
};
|
|
4
9
|
export declare abstract class SchemaHelper extends DatabaseHelper {
|
|
5
10
|
isOneOfClients(clients: Clients[]): boolean;
|
|
6
11
|
changeNullable(table: string, column: string, nullable: boolean): Promise<void>;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
default?: any;
|
|
10
|
-
}): Promise<void>;
|
|
11
|
-
changeToInteger(table: string, column: string, options?: {
|
|
12
|
-
nullable?: boolean;
|
|
13
|
-
default?: any;
|
|
14
|
-
}): Promise<void>;
|
|
15
|
-
changeToString(table: string, column: string, options?: {
|
|
16
|
-
nullable?: boolean;
|
|
17
|
-
default?: any;
|
|
18
|
-
length?: number;
|
|
19
|
-
}): Promise<void>;
|
|
20
|
-
protected changeToTypeByCopy<Options extends {
|
|
21
|
-
nullable?: boolean;
|
|
22
|
-
default?: any;
|
|
23
|
-
}>(table: string, column: string, options: Options, cb: (builder: Knex.CreateTableBuilder, column: string, options: Options) => Knex.ColumnBuilder): Promise<void>;
|
|
12
|
+
changeToType(table: string, column: string, type: typeof KNEX_TYPES[number], options?: Options): Promise<void>;
|
|
13
|
+
protected changeToTypeByCopy(table: string, column: string, type: typeof KNEX_TYPES[number], options: Options): Promise<void>;
|
|
24
14
|
preColumnDelete(): Promise<boolean>;
|
|
25
15
|
postColumnDelete(): Promise<void>;
|
|
26
16
|
}
|
|
@@ -17,9 +17,9 @@ class SchemaHelper extends types_1.DatabaseHelper {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
async
|
|
20
|
+
async changeToType(table, column, type, options = {}) {
|
|
21
21
|
await this.knex.schema.alterTable(table, (builder) => {
|
|
22
|
-
const b = builder.string(column);
|
|
22
|
+
const b = type === 'string' ? builder.string(column, options.length) : builder[type](column);
|
|
23
23
|
if (options.nullable === true) {
|
|
24
24
|
b.nullable();
|
|
25
25
|
}
|
|
@@ -32,39 +32,10 @@ class SchemaHelper extends types_1.DatabaseHelper {
|
|
|
32
32
|
b.alter();
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
async
|
|
35
|
+
async changeToTypeByCopy(table, column, type, options) {
|
|
36
|
+
const tempName = `${column}__temp`;
|
|
36
37
|
await this.knex.schema.alterTable(table, (builder) => {
|
|
37
|
-
const
|
|
38
|
-
if (options.nullable === true) {
|
|
39
|
-
b.nullable();
|
|
40
|
-
}
|
|
41
|
-
if (options.nullable === false) {
|
|
42
|
-
b.notNullable();
|
|
43
|
-
}
|
|
44
|
-
if (options.default !== undefined) {
|
|
45
|
-
b.defaultTo(options.default);
|
|
46
|
-
}
|
|
47
|
-
b.alter();
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
async changeToString(table, column, options = {}) {
|
|
51
|
-
await this.knex.schema.alterTable(table, (builder) => {
|
|
52
|
-
const b = builder.string(column, options.length);
|
|
53
|
-
if (options.nullable === true) {
|
|
54
|
-
b.nullable();
|
|
55
|
-
}
|
|
56
|
-
if (options.nullable === false) {
|
|
57
|
-
b.notNullable();
|
|
58
|
-
}
|
|
59
|
-
if (options.default !== undefined) {
|
|
60
|
-
b.defaultTo(options.default);
|
|
61
|
-
}
|
|
62
|
-
b.alter();
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
async changeToTypeByCopy(table, column, options, cb) {
|
|
66
|
-
await this.knex.schema.alterTable(table, (builder) => {
|
|
67
|
-
const col = cb(builder, `${column}__temp`, options);
|
|
38
|
+
const col = type === 'string' ? builder.string(tempName, options.length) : builder[type](tempName);
|
|
68
39
|
if (options.default !== undefined) {
|
|
69
40
|
col.defaultTo(options.default);
|
|
70
41
|
}
|
|
@@ -72,12 +43,12 @@ class SchemaHelper extends types_1.DatabaseHelper {
|
|
|
72
43
|
// the table)
|
|
73
44
|
col.nullable();
|
|
74
45
|
});
|
|
75
|
-
await this.knex(table).update(
|
|
46
|
+
await this.knex(table).update(tempName, this.knex.ref(column));
|
|
76
47
|
await this.knex.schema.alterTable(table, (builder) => {
|
|
77
48
|
builder.dropColumn(column);
|
|
78
49
|
});
|
|
79
50
|
await this.knex.schema.alterTable(table, (builder) => {
|
|
80
|
-
builder.renameColumn(
|
|
51
|
+
builder.renameColumn(tempName, column);
|
|
81
52
|
});
|
|
82
53
|
// We're altering the temporary column here. That starts nullable, so we only want to set it
|
|
83
54
|
// to NOT NULL when applicable
|
|
@@ -4,11 +4,12 @@ exports.down = exports.up = void 0;
|
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
async function up(knex) {
|
|
6
6
|
const helper = (0, helpers_1.getHelpers)(knex).schema;
|
|
7
|
-
|
|
7
|
+
const type = helper.isOneOfClients(['oracle', 'cockroachdb']) ? 'text' : 'string';
|
|
8
|
+
await helper.changeToType('directus_webhooks', 'url', type);
|
|
8
9
|
}
|
|
9
10
|
exports.up = up;
|
|
10
11
|
async function down(knex) {
|
|
11
|
-
await (0, helpers_1.getHelpers)(knex).schema.
|
|
12
|
+
await (0, helpers_1.getHelpers)(knex).schema.changeToType('directus_webhooks', 'url', 'string', {
|
|
12
13
|
nullable: false,
|
|
13
14
|
length: 255,
|
|
14
15
|
});
|
|
@@ -4,11 +4,12 @@ exports.down = exports.up = void 0;
|
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
async function up(knex) {
|
|
6
6
|
const helper = (0, helpers_1.getHelpers)(knex).schema;
|
|
7
|
-
|
|
7
|
+
const type = helper.isOneOfClients(['oracle', 'cockroachdb']) ? 'text' : 'string';
|
|
8
|
+
await helper.changeToType('directus_webhooks', 'collections', type);
|
|
8
9
|
}
|
|
9
10
|
exports.up = up;
|
|
10
11
|
async function down(knex) {
|
|
11
|
-
await (0, helpers_1.getHelpers)(knex).schema.
|
|
12
|
+
await (0, helpers_1.getHelpers)(knex).schema.changeToType('directus_webhooks', 'collections', 'string', {
|
|
12
13
|
nullable: false,
|
|
13
14
|
length: 255,
|
|
14
15
|
});
|
|
@@ -4,7 +4,7 @@ exports.down = exports.up = void 0;
|
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
async function up(knex) {
|
|
6
6
|
const helper = (0, helpers_1.getHelpers)(knex).schema;
|
|
7
|
-
await helper.
|
|
7
|
+
await helper.changeToType('directus_files', 'filesize', 'integer', {
|
|
8
8
|
nullable: true,
|
|
9
9
|
default: null,
|
|
10
10
|
});
|
|
@@ -12,7 +12,7 @@ async function up(knex) {
|
|
|
12
12
|
exports.up = up;
|
|
13
13
|
async function down(knex) {
|
|
14
14
|
const helper = (0, helpers_1.getHelpers)(knex).schema;
|
|
15
|
-
await helper.
|
|
15
|
+
await helper.changeToType('directus_files', 'filesize', 'integer', {
|
|
16
16
|
nullable: false,
|
|
17
17
|
default: 0,
|
|
18
18
|
});
|
|
@@ -9,10 +9,10 @@ async function up(knex) {
|
|
|
9
9
|
table.string('one_deselect_action').defaultTo('nullify');
|
|
10
10
|
});
|
|
11
11
|
await knex('directus_relations').update({ one_deselect_action: 'nullify' });
|
|
12
|
-
await helper.
|
|
12
|
+
await helper.changeToType('directus_relations', 'sort_field', 'string', {
|
|
13
13
|
length: 64,
|
|
14
14
|
});
|
|
15
|
-
await helper.
|
|
15
|
+
await helper.changeToType('directus_relations', 'one_deselect_action', 'string', {
|
|
16
16
|
nullable: false,
|
|
17
17
|
default: 'nullify',
|
|
18
18
|
});
|
|
@@ -20,7 +20,7 @@ async function up(knex) {
|
|
|
20
20
|
exports.up = up;
|
|
21
21
|
async function down(knex) {
|
|
22
22
|
const helper = (0, helpers_1.getHelpers)(knex).schema;
|
|
23
|
-
await helper.
|
|
23
|
+
await helper.changeToType('directus_relations', 'sort_field', 'string', {
|
|
24
24
|
length: 255,
|
|
25
25
|
});
|
|
26
26
|
await knex.schema.alterTable('directus_relations', (table) => {
|
|
@@ -11,7 +11,7 @@ async function up(knex) {
|
|
|
11
11
|
table.string('provider', 128).notNullable().defaultTo('default');
|
|
12
12
|
table.string('external_identifier').unique();
|
|
13
13
|
});
|
|
14
|
-
await helper.
|
|
14
|
+
await helper.changeToType('directus_users', 'email', 'string', {
|
|
15
15
|
nullable: true,
|
|
16
16
|
length: 128,
|
|
17
17
|
});
|
|
@@ -29,7 +29,7 @@ async function down(knex) {
|
|
|
29
29
|
table.dropColumn('provider');
|
|
30
30
|
table.dropColumn('external_identifier');
|
|
31
31
|
});
|
|
32
|
-
await helper.
|
|
32
|
+
await helper.changeToType('directus_users', 'email', 'string', {
|
|
33
33
|
nullable: false,
|
|
34
34
|
length: 128,
|
|
35
35
|
});
|
|
@@ -4,13 +4,15 @@ exports.down = exports.up = void 0;
|
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
async function up(knex) {
|
|
6
6
|
const helper = (0, helpers_1.getHelpers)(knex).schema;
|
|
7
|
-
|
|
7
|
+
const type = helper.isOneOfClients(['oracle', 'cockroachdb']) ? 'text' : 'string';
|
|
8
|
+
await helper.changeToType('directus_webhooks', 'collections', type, {
|
|
8
9
|
nullable: false,
|
|
9
10
|
});
|
|
10
11
|
}
|
|
11
12
|
exports.up = up;
|
|
12
13
|
async function down(knex) {
|
|
13
14
|
const helper = (0, helpers_1.getHelpers)(knex).schema;
|
|
14
|
-
|
|
15
|
+
const type = helper.isOneOfClients(['oracle', 'cockroachdb']) ? 'text' : 'string';
|
|
16
|
+
await helper.changeToType('directus_webhooks', 'collections', type);
|
|
15
17
|
}
|
|
16
18
|
exports.down = down;
|
|
@@ -9,7 +9,7 @@ async function up(knex) {
|
|
|
9
9
|
// "20201105B-change-webhook-url-type.ts"
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
await helper.
|
|
12
|
+
await helper.changeToType('directus_webhooks', 'url', 'string', {
|
|
13
13
|
nullable: false,
|
|
14
14
|
});
|
|
15
15
|
}
|
|
@@ -21,6 +21,6 @@ async function down(knex) {
|
|
|
21
21
|
// "20201105B-change-webhook-url-type.ts"
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
await helper.
|
|
24
|
+
await helper.changeToType('directus_webhooks', 'url', 'string');
|
|
25
25
|
}
|
|
26
26
|
exports.down = down;
|
|
@@ -4,7 +4,7 @@ exports.down = exports.up = void 0;
|
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
async function up(knex) {
|
|
6
6
|
const helper = (0, helpers_1.getHelpers)(knex).schema;
|
|
7
|
-
await helper.
|
|
7
|
+
await helper.changeToType('directus_settings', 'project_color', 'string', {
|
|
8
8
|
nullable: true,
|
|
9
9
|
default: null,
|
|
10
10
|
length: 50,
|
|
@@ -13,7 +13,7 @@ async function up(knex) {
|
|
|
13
13
|
exports.up = up;
|
|
14
14
|
async function down(knex) {
|
|
15
15
|
const helper = (0, helpers_1.getHelpers)(knex).schema;
|
|
16
|
-
await helper.
|
|
16
|
+
await helper.changeToType('directus_settings', 'project_color', 'string', {
|
|
17
17
|
nullable: true,
|
|
18
18
|
default: '#00C897',
|
|
19
19
|
length: 10,
|
|
@@ -7,7 +7,7 @@ async function up(knex) {
|
|
|
7
7
|
await knex.schema.alterTable('directus_settings', (table) => {
|
|
8
8
|
table.string('default_language').notNullable().defaultTo('en-US');
|
|
9
9
|
});
|
|
10
|
-
await helper.
|
|
10
|
+
await helper.changeToType('directus_users', 'language', 'string', {
|
|
11
11
|
nullable: true,
|
|
12
12
|
default: null,
|
|
13
13
|
length: 255,
|
|
@@ -19,7 +19,7 @@ async function down(knex) {
|
|
|
19
19
|
await knex.schema.alterTable('directus_settings', (table) => {
|
|
20
20
|
table.dropColumn('default_language');
|
|
21
21
|
});
|
|
22
|
-
await helper.
|
|
22
|
+
await helper.changeToType('directus_users', 'language', 'string', {
|
|
23
23
|
nullable: true,
|
|
24
24
|
default: 'en-US',
|
|
25
25
|
length: 255,
|