Added last login column to users table.
This commit is contained in:
parent
a586413240
commit
153f28c494
|
@ -1,25 +0,0 @@
|
||||||
exports.up = async (knex) => knex.raw(`
|
|
||||||
CREATE MATERIALIZED VIEW entities_stats
|
|
||||||
AS
|
|
||||||
WITH RECURSIVE relations AS (
|
|
||||||
SELECT entities.id, entities.parent_id, count(releases.id) AS releases_count, count(releases.id) AS total_count
|
|
||||||
FROM entities
|
|
||||||
LEFT JOIN releases ON releases.entity_id = entities.id
|
|
||||||
GROUP BY entities.id
|
|
||||||
|
|
||||||
UNION ALL
|
|
||||||
|
|
||||||
SELECT entities.id AS entity_id, count(releases.id) AS releases_count, count(releases.id) + relations.total_count AS total_count
|
|
||||||
FROM entities
|
|
||||||
INNER JOIN relations ON relations.id = entities.parent_id
|
|
||||||
LEFT JOIN releases ON releases.entity_id = entities.id
|
|
||||||
GROUP BY entities.id
|
|
||||||
)
|
|
||||||
|
|
||||||
SELECT relations.id AS entity_id, relations.releases_count
|
|
||||||
FROM relations;
|
|
||||||
`);
|
|
||||||
|
|
||||||
exports.down = async (knex) => knex.raw(`
|
|
||||||
DROP MATERIALIZED VIEW entities_stats;
|
|
||||||
`);
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
exports.up = async (knex) => knex.schema.alterTable('users', (table) => {
|
||||||
|
table.datetime('last_login');
|
||||||
|
});
|
||||||
|
|
||||||
|
exports.down = async (knex) => knex.schema.alterTable('users', (table) => {
|
||||||
|
table.dropColumn('last_login');
|
||||||
|
});
|
|
@ -1,10 +1,23 @@
|
||||||
exports.up = async (knex) => knex.raw(`
|
exports.up = async (knex) => knex.raw(`
|
||||||
CREATE MATERIALIZED VIEW entities_stats
|
CREATE MATERIALIZED VIEW entities_stats
|
||||||
AS
|
AS
|
||||||
SELECT entities.id AS entity_id, count(releases.id) AS releases_count
|
WITH RECURSIVE relations AS (
|
||||||
|
SELECT entities.id, entities.parent_id, count(releases.id) AS releases_count, count(releases.id) AS total_count
|
||||||
FROM entities
|
FROM entities
|
||||||
LEFT JOIN releases ON releases.entity_id = entities.id
|
LEFT JOIN releases ON releases.entity_id = entities.id
|
||||||
GROUP BY entities.id;
|
GROUP BY entities.id
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT entities.id AS entity_id, count(releases.id) AS releases_count, count(releases.id) + relations.total_count AS total_count
|
||||||
|
FROM entities
|
||||||
|
INNER JOIN relations ON relations.id = entities.parent_id
|
||||||
|
LEFT JOIN releases ON releases.entity_id = entities.id
|
||||||
|
GROUP BY entities.id
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT relations.id AS entity_id, relations.releases_count
|
||||||
|
FROM relations;
|
||||||
`);
|
`);
|
||||||
|
|
||||||
exports.down = async (knex) => knex.raw(`
|
exports.down = async (knex) => knex.raw(`
|
||||||
|
|
|
@ -34,6 +34,10 @@ async function login(credentials) {
|
||||||
|
|
||||||
await verifyPassword(credentials.password, user.password);
|
await verifyPassword(credentials.password, user.password);
|
||||||
|
|
||||||
|
await knex('users')
|
||||||
|
.update('last_login', 'NOW()')
|
||||||
|
.where('id', user.id);
|
||||||
|
|
||||||
return curateUser(user);
|
return curateUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue