File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed
Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change 1+ import { sql } from '@silverhand/slonik' ;
2+
3+ import type { AlterationScript } from '../lib/types/alteration.js' ;
4+
5+ const alteration : AlterationScript = {
6+ up : async ( pool ) => {
7+ // Add new columns for user and m2m token usage tracking
8+ await pool . query ( sql `
9+ alter table daily_token_usage
10+ add column user_token_usage bigint not null default 0,
11+ add column m2m_token_usage bigint not null default 0;
12+ ` ) ;
13+
14+ // Remove foreign key constraint to support enterprise tenant deletion requirements
15+ await pool . query ( sql `
16+ alter table daily_token_usage
17+ drop constraint if exists daily_token_usage_tenant_id_fkey;
18+ ` ) ;
19+ } ,
20+ down : async ( pool ) => {
21+ // Remove the new columns
22+ await pool . query ( sql `
23+ alter table daily_token_usage
24+ drop column if exists user_token_usage,
25+ drop column if exists m2m_token_usage;
26+ ` ) ;
27+
28+ // Re-add the foreign key constraint
29+ await pool . query ( sql `
30+ alter table daily_token_usage
31+ add constraint daily_token_usage_tenant_id_fkey
32+ foreign key (tenant_id) references tenants (id) on update cascade on delete cascade;
33+ ` ) ;
34+ } ,
35+ } ;
36+
37+ export default alteration ;
Original file line number Diff line number Diff line change 11create table daily_token_usage (
22 id varchar (21 ) not null ,
3- tenant_id varchar (21 ) not null
4- references tenants (id) on update cascade on delete cascade ,
3+ tenant_id varchar (21 ) not null ,
54 usage bigint not null default(0 ),
5+ user_token_usage bigint not null default(0 ),
6+ m2m_token_usage bigint not null default(0 ),
67 date timestamptz not null ,
78 primary key (id)
89);
You can’t perform that action at this time.
0 commit comments