Skip to content

Commit

Permalink
run prettier on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickmehaffy committed Sep 30, 2022
1 parent 74d9a8d commit c88a779
Show file tree
Hide file tree
Showing 21 changed files with 316 additions and 338 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
14 changes: 7 additions & 7 deletions v3-sql-v4-sql/config/database.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const knex = require("knex");
const knex = require('knex');

let additionalConfigV3 = {};
let additionalConfigV4 = {};

if (process.env.DATABASE_CLIENT === "sqlite") {
if (process.env.DATABASE_CLIENT === 'sqlite') {
additionalConfigV3 = {
useNullAsDefault: true,
connection: {
Expand All @@ -19,7 +19,7 @@ if (process.env.DATABASE_CLIENT === "sqlite") {
};
}

if (process.env.DATABASE_CLIENT === "pg") {
if (process.env.DATABASE_CLIENT === 'pg') {
additionalConfigV3 = {
connection: {
host: process.env.DATABASE_V3_HOST,
Expand All @@ -42,7 +42,7 @@ if (process.env.DATABASE_CLIENT === "pg") {
};
}

if (process.env.DATABASE_CLIENT === "mysql") {
if (process.env.DATABASE_CLIENT === 'mysql') {
additionalConfigV3 = {
connection: {
host: process.env.DATABASE_V3_HOST,
Expand Down Expand Up @@ -75,9 +75,9 @@ const dbV4 = knex({
...additionalConfigV4,
});

const isPGSQL = dbV3.client.config.client === "pg";
const isSQLITE = dbV3.client.config.client === "sqlite";
const isMYSQL = dbV3.client.config.client === "mysql";
const isPGSQL = dbV3.client.config.client === 'pg';
const isSQLITE = dbV3.client.config.client === 'sqlite';
const isMYSQL = dbV3.client.config.client === 'mysql';

module.exports = {
dbV3,
Expand Down
4 changes: 2 additions & 2 deletions v3-sql-v4-sql/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("dotenv").config();
require('dotenv').config();

const { migrate } = require("./migrate");
const { migrate } = require('./migrate');

async function f() {
await migrate();
Expand Down
45 changes: 19 additions & 26 deletions v3-sql-v4-sql/migrate/helpers/adminHelpers.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
const {
dbV3,
dbV4,
isPGSQL,
isSQLITE,
isMYSQL,
} = require("../../config/database");
const { BATCH_SIZE, SUPER_ADMIN } = require("./constants");
const { resetTableSequence } = require("./migrate");
const { migrateItems } = require("./migrateFields");
const { migrateUids } = require("./migrateValues");
const pluralize = require("pluralize");
const { camelCase } = require("lodash");
const { resolveDestTableName, resolveSourceTableName } = require("./tableNameHelpers");
const { dbV3, dbV4, isPGSQL, isSQLITE, isMYSQL } = require('../../config/database');
const { BATCH_SIZE, SUPER_ADMIN } = require('./constants');
const { resetTableSequence } = require('./migrate');
const { migrateItems } = require('./migrateFields');
const { migrateUids } = require('./migrateValues');
const pluralize = require('pluralize');
const { camelCase } = require('lodash');
const { resolveDestTableName, resolveSourceTableName } = require('./tableNameHelpers');

const extraV4Permissions = [
{ action: "admin::api-tokens.create", properties: {}, conditions: [] },
{ action: "admin::api-tokens.delete", properties: {}, conditions: [] },
{ action: "admin::api-tokens.read", properties: {}, conditions: [] },
{ action: "admin::api-tokens.update", properties: {}, conditions: [] },
{ action: 'admin::api-tokens.create', properties: {}, conditions: [] },
{ action: 'admin::api-tokens.delete', properties: {}, conditions: [] },
{ action: 'admin::api-tokens.read', properties: {}, conditions: [] },
{ action: 'admin::api-tokens.update', properties: {}, conditions: [] },
];

function migrateSubject(subject) {
if (subject) {
return subject
.split(".")
.split('.')
.map((s) => migrateUids(pluralize(s, 1)))
.join(".");
.join('.');
}
return subject;
}
Expand All @@ -38,14 +32,13 @@ function migrateProperties(properties) {
return properties;
}


async function migrateAdminPermissions() {
const source = "strapi_permission";
const destination = "admin_permissions";
const destinationLinks = "admin_permissions_role_links";
const source = 'strapi_permission';
const destination = 'admin_permissions';
const destinationLinks = 'admin_permissions_role_links';
const count =
(await dbV3(resolveSourceTableName(source)).count().first()).count ||
(await dbV3(resolveSourceTableName(source)).count().first())["count(*)"];
(await dbV3(resolveSourceTableName(source)).count().first())['count(*)'];
console.log(`Migrating ${count} items from ${source} to ${destination}`);
await dbV4(resolveDestTableName(destinationLinks)).del();
await dbV4(resolveDestTableName(destination)).del();
Expand Down Expand Up @@ -73,7 +66,7 @@ async function migrateAdminPermissions() {
let ids = [];

if (isPGSQL) {
ids = await dbV4(resolveDestTableName(destination)).insert(extraV4Permissions).returning("id");
ids = await dbV4(resolveDestTableName(destination)).insert(extraV4Permissions).returning('id');
}

if (isSQLITE) {
Expand Down
2 changes: 1 addition & 1 deletion v3-sql-v4-sql/migrate/helpers/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { isPGSQL } = require("../../config/database");
const { isPGSQL } = require('../../config/database');

const BATCH_SIZE = process.env.BATCH_SIZE || 50;
const SUPER_ADMIN = 1;
Expand Down
72 changes: 36 additions & 36 deletions v3-sql-v4-sql/migrate/helpers/coreStoreHelpers.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
const apiTokenEntry = {
key: "plugin_content_manager_configuration_content_types::admin::api-token",
type: "object",
key: 'plugin_content_manager_configuration_content_types::admin::api-token',
type: 'object',
environment: null,
tag: null,
value: {
uid: "admin::api-token",
uid: 'admin::api-token',
settings: {
bulkable: true,
filterable: true,
searchable: true,
pageSize: 10,
mainField: "name",
defaultSortBy: "name",
defaultSortOrder: "ASC",
mainField: 'name',
defaultSortBy: 'name',
defaultSortOrder: 'ASC',
},
metadatas: {
id: { edit: {}, list: { label: "id", searchable: true, sortable: true } },
id: { edit: {}, list: { label: 'id', searchable: true, sortable: true } },
name: {
edit: {
label: "name",
description: "",
placeholder: "",
label: 'name',
description: '',
placeholder: '',
visible: true,
editable: true,
},
list: { label: "name", searchable: true, sortable: true },
list: { label: 'name', searchable: true, sortable: true },
},
description: {
edit: {
label: "description",
description: "",
placeholder: "",
label: 'description',
description: '',
placeholder: '',
visible: true,
editable: true,
},
list: { label: "description", searchable: true, sortable: true },
list: { label: 'description', searchable: true, sortable: true },
},
type: {
edit: {
label: "type",
description: "",
placeholder: "",
label: 'type',
description: '',
placeholder: '',
visible: true,
editable: true,
},
list: { label: "type", searchable: true, sortable: true },
list: { label: 'type', searchable: true, sortable: true },
},
accessKey: {
edit: {
label: "accessKey",
description: "",
placeholder: "",
label: 'accessKey',
description: '',
placeholder: '',
visible: true,
editable: true,
},
list: { label: "accessKey", searchable: true, sortable: true },
list: { label: 'accessKey', searchable: true, sortable: true },
},
createdAt: {
edit: {
label: "createdAt",
description: "",
placeholder: "",
label: 'createdAt',
description: '',
placeholder: '',
visible: false,
editable: true,
},
list: { label: "createdAt", searchable: true, sortable: true },
list: { label: 'createdAt', searchable: true, sortable: true },
},
updatedAt: {
edit: {
label: "updatedAt",
description: "",
placeholder: "",
label: 'updatedAt',
description: '',
placeholder: '',
visible: false,
editable: true,
},
list: { label: "updatedAt", searchable: true, sortable: true },
list: { label: 'updatedAt', searchable: true, sortable: true },
},
},
layouts: {
list: ["id", "name", "description", "type"],
list: ['id', 'name', 'description', 'type'],
editRelations: [],
edit: [
[
{ name: "name", size: 6 },
{ name: "description", size: 6 },
{ name: 'name', size: 6 },
{ name: 'description', size: 6 },
],
[
{ name: "type", size: 6 },
{ name: "accessKey", size: 6 },
{ name: 'type', size: 6 },
{ name: 'accessKey', size: 6 },
],
],
},
Expand Down
14 changes: 6 additions & 8 deletions v3-sql-v4-sql/migrate/helpers/migrateFields.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { snakeCase } = require("lodash/fp");
const { snakeCase } = require('lodash/fp');

function migrateField(fieldName) {
switch (fieldName) {
case "created_by":
return "created_by_id";
case "updated_by":
return "updated_by_id";
case 'created_by':
return 'created_by_id';
case 'updated_by':
return 'updated_by_id';
default:
return snakeCase(fieldName);
}
Expand All @@ -21,9 +21,7 @@ function migrateItem(item) {
}

function migrateItems(items, itemMapper = undefined) {
return items
.map(itemMapper ?? migrateItem)
.filter((item) => item !== undefined);
return items.map(itemMapper ?? migrateItem).filter((item) => item !== undefined);
}

module.exports = {
Expand Down
17 changes: 7 additions & 10 deletions v3-sql-v4-sql/migrate/helpers/migrateValues.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
const { cloneDeepWith, camelCase, isObject, isString } = require("lodash");
const { cloneDeepWith, camelCase, isObject, isString } = require('lodash');

function migrateUids(uid) {
if (!uid) {
return uid;
}
var result = uid;
result = result.replace("strapi::", "admin::");
result = result.replace("application::", "api::");
result = result.replace(
"plugins::users-permission",
"plugin::users-permissions"
);
result = result.replace("plugins::", "plugin::");
result = result.replace('strapi::', 'admin::');
result = result.replace('application::', 'api::');
result = result.replace('plugins::users-permission', 'plugin::users-permissions');
result = result.replace('plugins::', 'plugin::');
return result;
}

function migrateItemValues(item) {
return cloneDeepWith(item, (value, key) => {
if (key === "label" && !isObject(value)) {
if (key === 'label' && !isObject(value)) {
return camelCase(value);
}
if (key === "uid" && !isObject(value)) {
if (key === 'uid' && !isObject(value)) {
return migrateUids(value);
}
});
Expand Down
4 changes: 3 additions & 1 deletion v3-sql-v4-sql/migrate/helpers/relationHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ async function migrateRelations(tables, relations) {

if (isPGSQL) {
v4Tables = (
await dbV4('information_schema.tables').select('table_name').where('table_schema', process.env.DATABASE_V4_SCHEMA)
await dbV4('information_schema.tables')
.select('table_name')
.where('table_schema', process.env.DATABASE_V4_SCHEMA)
).map((row) => row.table_name);
}

Expand Down
6 changes: 3 additions & 3 deletions v3-sql-v4-sql/migrate/helpers/tableNameHelpers.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const { isPGSQL } = require("../../config/database");
const { isPGSQL } = require('../../config/database');

const resolveSourceTableName = (name) => {
if (isPGSQL) {
return process.env.DATABASE_V3_SCHEMA + "." + name;
return process.env.DATABASE_V3_SCHEMA + '.' + name;
}

return name;
};

const resolveDestTableName = (name) => {
if (isPGSQL) {
return process.env.DATABASE_V4_SCHEMA + "." + name;
return process.env.DATABASE_V4_SCHEMA + '.' + name;
}

return name;
Expand Down
Loading

0 comments on commit c88a779

Please sign in to comment.