mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(core, schemas): enhance the time accuracy of dau data (#5451)
This commit is contained in:
parent
c1f978c574
commit
c65730bcd2
3 changed files with 19 additions and 3 deletions
|
@ -1,6 +1,5 @@
|
|||
import { generateStandardId } from '@logto/shared';
|
||||
|
||||
import { getUtcStartOfTheDay } from '#src/oidc/utils.js';
|
||||
import type Queries from '#src/tenants/Queries.js';
|
||||
|
||||
export const recordActiveUsers = async (accessToken: { accountId?: string }, queries: Queries) => {
|
||||
|
@ -16,6 +15,5 @@ export const recordActiveUsers = async (accessToken: { accountId?: string }, que
|
|||
await insertActiveUser({
|
||||
id: generateStandardId(),
|
||||
userId: accountId,
|
||||
date: getUtcStartOfTheDay(new Date()).getTime(),
|
||||
});
|
||||
};
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
import { sql } from 'slonik';
|
||||
|
||||
import type { AlterationScript } from '../lib/types/alteration.js';
|
||||
|
||||
const alteration: AlterationScript = {
|
||||
up: async (pool) => {
|
||||
await pool.query(sql`
|
||||
alter table daily_active_users alter column date set default now();
|
||||
`);
|
||||
},
|
||||
down: async (pool) => {
|
||||
await pool.query(sql`
|
||||
alter table daily_active_users alter column date drop default;
|
||||
`);
|
||||
},
|
||||
};
|
||||
|
||||
export default alteration;
|
|
@ -3,7 +3,7 @@ create table daily_active_users (
|
|||
tenant_id varchar(21) not null
|
||||
references tenants (id) on update cascade on delete cascade,
|
||||
user_id varchar(21) not null,
|
||||
date timestamptz not null,
|
||||
date timestamptz not null default (now()),
|
||||
primary key (id),
|
||||
constraint daily_active_users__user_id_date
|
||||
unique (user_id, date)
|
||||
|
|
Loading…
Reference in a new issue