Skip to content

Commit

Permalink
Setting up migrations int the application (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Gonzalez committed Apr 14, 2023
1 parent 1a912c6 commit 0d4090b
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 22,951 deletions.
3 changes: 2 additions & 1 deletion api/podcast/services/podcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

module.exports = {
async findOneByIdentifier(identifier) {
return await strapi.models.podcast.findOne({identifier}).populate(['episodes']);
// return await strapi.models.podcast.findOne({identifier}).populate(['episodes']);
return await strapi.query('podcast').findOne({identifier});
},
};
2 changes: 0 additions & 2 deletions api/sitemap/controllers/Sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module.exports = {
}
};

// const sort = {'publishedAt': -1};
// const query = {publishedAt: {$lte: new Date()}, enable: true};
const res = await strapi.query('post').model.query(qb => {
qb.orderBy('publishedAt', 'ASC');
qb.whereRaw('publishedAt < ? AND enable = 1', [new Date().toISOString().slice(0, 19).replace('T', ' ')]);
Expand Down
17 changes: 17 additions & 0 deletions config/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = ({ env }) => ({
// apiToken: {
// salt: env('API_TOKEN_SALT', 'someRandomLongString'),
// },
// auditLogs: { // only accessible with an Enterprise plan
// enabled: env.bool('AUDIT_LOGS_ENABLED', true),
// },
auth: {
secret: env('ADMIN_JWT_SECRET', 'someSecretKey'),
},
// transfer: {
// token: {
// salt: env('TRANSFER_TOKEN_SALT', 'anotherRandomLongString'),
// }
// },
autoOpen: false
});
4 changes: 4 additions & 0 deletions config/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module.exports = ({env}) => ({
password: 'password',
port: env.int('DATABASE_PORT', 3306),
host: '127.0.0.1',
migrations: {
directory: './migrations',
tableName: 'migrations'
}
},
options: {},
}
Expand Down
17 changes: 17 additions & 0 deletions config/env/test/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = ({ env }) => ({
// apiToken: {
// salt: env('API_TOKEN_SALT', 'someRandomLongString'),
// },
// auditLogs: { // only accessible with an Enterprise plan
// enabled: env.bool('AUDIT_LOGS_ENABLED', true),
// },
auth: {
secret: 'test-admin',
},
// transfer: {
// token: {
// salt: env('TRANSFER_TOKEN_SALT', 'anotherRandomLongString'),
// }
// },
autoOpen: false
});
4 changes: 4 additions & 0 deletions config/env/test/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module.exports = ({env}) => ({
settings: {
client: 'sqlite',
filename: env('DATABASE_FILENAME', './data/data.db'), // or specify the path to your db file
migrations: {
directory: './migrations',
tableName: 'migrations'
}
},
options: {
useNullAsDefault: true,
Expand Down
8 changes: 4 additions & 4 deletions config/env/test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module.exports = ({env}) => ({
cron: {
enabled: false
},
admin: {
autoOpen: false,
browser: false
}
// admin: {
// autoOpen: false,
// browser: false
// }
});
9 changes: 9 additions & 0 deletions config/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
'migrations': {
enabled: true,
config: {
autoStart: true,
migrationFolderPath : 'migrations'
},
},
};
12 changes: 6 additions & 6 deletions config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module.exports = ({env}) => ({
cron: {
enabled: true
},
admin: {
autoOpen: false,
auth: {
secret: env('ADMIN_JWT_SECRET', '6V#j7xt3ZHBgBphIiwv2')
}
}
// admin: {
// autoOpen: false,
// auth: {
// secret: env('ADMIN_JWT_SECRET', '6V#j7xt3ZHBgBphIiwv2')
// }
// }
});
31 changes: 31 additions & 0 deletions migrations/v1_initial_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
async function createRoleIfNotExist(type, name, description) {
let role = await strapi.query('role', 'users-permissions').findOne({type});
if (!role) {
role = await strapi.query('role', 'users-permissions').create({name, description, type});
}
return role;
}

async function updateRolePermissions(role, controller, action, enabled) {
await strapi.query('permission', 'users-permissions')
.update({role: role.id, controller, action}, {enabled});
}

module.exports = async () => {
let staffRole = await createRoleIfNotExist(
'staff', 'Staff', 'Users that can review the all the articles');
// let adminRole = await createRoleIfNotExist(
// 'administrator', 'Administrator', 'Administration control in the application');

const controllers = [{
name: 'episode',
actions: ['count', 'find', 'findone'],
enabled: true
}];

for (let controller of controllers) {
for (let action of controller.actions) {
await updateRolePermissions(staffRole, controller.name, action, controller.enabled);
}
}
};
Loading

0 comments on commit 0d4090b

Please sign in to comment.