Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #342

Merged
merged 5 commits into from
Oct 1, 2023
Merged

Dev #342

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions packages/evershop/bin/lib/bootstrap/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ const {
rollback
} = require('@evershop/postgres-query-builder');
const {
getConnection
getConnection,
pool
} = require('@evershop/evershop/src/lib/postgres/connection');
const { existsSync, readdirSync } = require('fs');
const { error } = require('@evershop/evershop/src/lib/log/debuger');
const { createMigrationTable } = require('../../install/createMigrationTable');

async function getCurrentInstalledVersion(module, connection) {
async function getCurrentInstalledVersion(module) {
/** Check for current installed version */
const check = await select()
.from('migration')
.where('module', '=', module)
.load(connection);
.load(pool);
if (!check) {
return '0.0.1';
} else {
return check.version;
}
}

async function migrateModule(module, connection) {
async function migrateModule(module) {
/** Check if the module has migration folder, if not ignore it */
if (!existsSync(path.resolve(module.path, 'migration'))) {
return;
Expand All @@ -42,17 +43,16 @@ async function migrateModule(module, connection) {
)
.map((dirent) => dirent.name.replace('Version-', '').replace('.js', ''))
.sort((first, second) => semver.lt(first, second));
const currentInstalledVersion = await getCurrentInstalledVersion(
module.name,
connection
);

const currentInstalledVersion = await getCurrentInstalledVersion(module.name);
// eslint-disable-next-line no-restricted-syntax
for (const version of migrations) {
/** If the version is lower or equal the installed version, ignore it */
if (semver.lte(version, currentInstalledVersion)) {
continue;
}

const connection = await getConnection();
await startTransaction(connection);
// eslint-disable-next-line no-await-in-loop
// eslint-disable-next-line global-require
/** We expect the migration script to provide a function as a default export */
Expand All @@ -69,7 +69,9 @@ async function migrateModule(module, connection) {
version
})
.execute(connection, false);
await commit(connection);
} catch (e) {
await rollback(connection);
throw new Error(
`Migration failed for module ${module.name}, version ${version}\n${e}`
);
Expand All @@ -78,18 +80,15 @@ async function migrateModule(module, connection) {
}

module.exports.migrate = async function migrate(modules) {
const connection = await getConnection();
await startTransaction(connection);
try {
const connection = await getConnection();
// Create a migration table if not exists. This is for the first time installation
await createMigrationTable(connection);
// eslint-disable-next-line no-restricted-syntax
for (const module of modules) {
await migrateModule(module, connection);
await migrateModule(module);
}
await commit(connection);
} catch (e) {
await rollback(connection);
error(e);
process.exit(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Shipment.propTypes = {

export const layout = `
query Query {
order(id: getContextValue("orderId")) {
order(uuid: getContextValue("orderId")) {
orderId
shippingNote
shippingMethod
Expand Down
12 changes: 4 additions & 8 deletions packages/evershop/src/lib/webpack/createBaseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,16 @@ module.exports.createBaseConfig = function createBaseConfig(isServer) {
};

config.optimization = {};

// Check if the flag --skip-minify is set
const skipMinify = process.argv.includes('--skip-minify');
if (isProductionMode()) {
config.optimization = Object.assign(config.optimization, {
minimize: true,
minimize: !skipMinify,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
// We want uglify-js to parse ecma 8 code. However, we don't want it
// to apply any minification steps that turns valid ecma 5 code
// into invalid ecma 5 code. This is why the 'compress' and 'output'
// sections only apply transformations that are ecma 5 safe
// https://github.com/facebook/create-react-app/pull/4234
ecma: 2020
},
compress: false,
Expand All @@ -176,8 +174,6 @@ module.exports.createBaseConfig = function createBaseConfig(isServer) {
output: {
ecma: 5,
comments: false,
// Turned on because emoji and regex is not minified properly using
// default. See https://github.com/facebook/create-react-app/issues/2488
ascii_only: true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ const { camelCase } = require('@evershop/evershop/src/lib/util/camelCase');

module.exports = {
Query: {
adminUser: async (root, { id }, { pool, user }) => {
if (!user) {
return null;
}
adminUser: async (root, { id }, { pool }) => {
const query = select().from('admin_user');
query.where('admin_user_id', '=', id);

const adminUser = await query.load(pool);
return adminUser ? camelCase(adminUser) : null;
},
currentAdminUser: (root, args, { user }) => (user ? camelCase(user) : null),
adminUsers: async (_, { filters = [] }, { pool, user }) => {
// This field is for admin only
if (!user) {
return [];
}
adminUsers: async (_, { filters = [] }, { pool }) => {
const query = select().from('admin_user');
const currentFilters = [];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Represents a single attribute group
"""
type AttributeGroup {
attributeGroupId: ID!
uuid: String!
groupName: String!
updateApi: String!
attributes: [Attribute]
}

extend type Attribute {
groups: [AttributeGroup]
editUrl: String!
updateApi: String!
deleteApi: String!
}

"""
Represents a collection of attributes
"""
type AttributeCollection {
items: [Attribute]
currentPage: Int!
total: Int!
currentFilters: [Filter]
}

"""
Represents a collection of attribute groups
"""
type AttributeGroupCollection {
items: [AttributeGroup]
currentPage: Int!
total: Int!
currentFilters: [Filter]
}

extend type Query {
attributes(filters: [FilterInput]): AttributeCollection
attributeGroups(filters: [FilterInput]): AttributeGroupCollection
}
Loading
Loading