mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
chore: create script for sqlite migration
This commit is contained in:
parent
cb6f5d7891
commit
30eebd0bcc
43
packages/utils/upgrade/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.code.ts
vendored
Normal file
43
packages/utils/upgrade/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.code.ts
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
import type { StringLiteral, Transform } from 'jscodeshift';
|
||||
|
||||
const transform: Transform = (file, api) => {
|
||||
const { j } = api;
|
||||
|
||||
// Parse the file content
|
||||
const root = j(file.source);
|
||||
|
||||
if (!file.path.includes('config/database.js')) {
|
||||
return file.source;
|
||||
}
|
||||
const targetProperties = new Set([
|
||||
'sqlite3',
|
||||
'vscode/sqlite3',
|
||||
'sqlite-legacy',
|
||||
'better-sqlite3',
|
||||
]);
|
||||
|
||||
return root
|
||||
.find(j.ObjectExpression)
|
||||
.forEach((path) => {
|
||||
j(path)
|
||||
.find(j.Property)
|
||||
.forEach((propertyPath) => {
|
||||
// Check if the property name is one of the targets
|
||||
const key = propertyPath.node.key;
|
||||
const propertyName = key.type === 'Identifier' ? key.name : (key as StringLiteral).value;
|
||||
|
||||
if (targetProperties.has(propertyName)) {
|
||||
// Rename the property to 'sqlite'
|
||||
if (key.type === 'Identifier') {
|
||||
key.name = 'sqlite';
|
||||
} else {
|
||||
// For Literal types
|
||||
(key as StringLiteral).value = 'sqlite';
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.toSource({ quote: 'single' });
|
||||
};
|
||||
|
||||
export default transform;
|
29
packages/utils/upgrade/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.json.ts
vendored
Normal file
29
packages/utils/upgrade/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.json.ts
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import type { modules } from '../../../dist';
|
||||
|
||||
const transform: modules.runner.json.JSONTransform = (file, params) => {
|
||||
const { cwd, json } = params;
|
||||
|
||||
const rootPackageJsonPath = path.join(cwd, 'package.json');
|
||||
|
||||
if (file.path !== rootPackageJsonPath) {
|
||||
return file.json;
|
||||
}
|
||||
|
||||
const j = json(file.json);
|
||||
|
||||
const targetProperties = ['sqlite3', 'vscode/sqlite3', 'sqlite-legacy'];
|
||||
|
||||
targetProperties.forEach((targetProperty) => {
|
||||
const oldSqliteDependency = `dependencies.${targetProperty}`;
|
||||
if (j.has(oldSqliteDependency)) {
|
||||
j.remove(oldSqliteDependency);
|
||||
j.set('dependencies.better-sqlite3', '9.0.0');
|
||||
}
|
||||
});
|
||||
|
||||
return j.root();
|
||||
};
|
||||
|
||||
export default transform;
|
@ -1,4 +1,4 @@
|
||||
import { cloneDeep, get, has, set, merge } from 'lodash/fp';
|
||||
import { cloneDeep, get, has, set, merge, omit } from 'lodash/fp';
|
||||
|
||||
import type { Utils } from '@strapi/types';
|
||||
|
||||
@ -31,6 +31,11 @@ export class JSONTransformAPI implements JSONTransformAPIInterface {
|
||||
return this;
|
||||
}
|
||||
|
||||
remove(path: string) {
|
||||
this.json = omit(path, this.json);
|
||||
return this;
|
||||
}
|
||||
|
||||
root(): Utils.JSONObject {
|
||||
return cloneDeep(this.json);
|
||||
}
|
||||
|
@ -8,4 +8,5 @@ export interface JSONTransformAPI {
|
||||
set(path: string, value: Utils.JSONValue): this;
|
||||
merge(other: Utils.JSONObject): this;
|
||||
root(): Utils.JSONObject;
|
||||
remove(path: string): this;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user