Skip to content

Commit 0d8607a

Browse files
authored
Merge branch 'main' into DLAPI-500-add-filters-to-delete-entry
2 parents 12bebf3 + 8cfa0cf commit 0d8607a

File tree

8 files changed

+58
-2
lines changed

8 files changed

+58
-2
lines changed

api/controllers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ export {
2424
resolveTenantController,
2525
requestSchema as resolveTenantRequestSchema,
2626
} from '../src/controllers/tenants/resolve-tenant';
27+
export {operation as operationModel} from '../src/controllers/response-models/operation';

src/components/zod/custom-types/limited-object.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export const limitedObject = ({limit}: {limit: number}) =>
1010
},
1111
{
1212
message: `Object can't contain more than ${limit} characters`,
13+
params: {code: 'OBJECT_SIZE_LIMIT_EXCEEDED'},
1314
},
1415
);

src/const/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export const ENCODED_ID_LENGTH = 13;
153153
export const MAX_META_OBJECT_SYMBOLS = 2000;
154154
export const MAX_UNVERSIONED_DATA_OBJECT_SYMBOLS = 5000;
155155
export const MAX_BRANDING_OBJECT_SYMBOLS = 15000;
156+
export const MAX_STATE_DATA_OBJECT_SYMBOLS = 50000;
156157

157158
export const AJV_PATTERN_KEYS_NOT_OBJECT = {
158159
'.*': {

src/controllers/states/create-state.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {AppRouteHandler} from '@gravity-ui/expresskit';
22

33
import {ApiTag} from '../../components/api-docs';
44
import {makeReqParser, z, zc} from '../../components/zod';
5-
import {CONTENT_TYPE_JSON} from '../../const';
5+
import {CONTENT_TYPE_JSON, MAX_STATE_DATA_OBJECT_SYMBOLS} from '../../const';
66
import {createState} from '../../services/new/state';
77

88
import {stateHashModel} from './response-models';
@@ -12,7 +12,9 @@ const requestSchema = {
1212
entryId: zc.encodedId(),
1313
}),
1414
body: z.object({
15-
data: z.record(z.string(), z.unknown()),
15+
data: zc.limitedObject({
16+
limit: MAX_STATE_DATA_OBJECT_SYMBOLS,
17+
}),
1618
}),
1719
};
1820

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type {Knex} from 'knex';
2+
3+
export async function up(knex: Knex): Promise<void> {
4+
await knex.raw(`
5+
ALTER TABLE user_settings
6+
ADD COLUMN tenant_id TEXT NOT NULL DEFAULT 'common'
7+
REFERENCES tenants (tenant_id) ON UPDATE CASCADE ON DELETE CASCADE;
8+
`);
9+
}
10+
11+
export async function down(knex: Knex): Promise<void> {
12+
await knex.raw(`
13+
ALTER TABLE user_settings DROP COLUMN tenant_id;
14+
`);
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type {Knex} from 'knex';
2+
3+
export async function up(knex: Knex): Promise<void> {
4+
await knex.raw(
5+
`CREATE UNIQUE INDEX CONCURRENTLY user_settings_user_id_tenant_id_idx ON user_settings (user_id, tenant_id);`,
6+
);
7+
}
8+
9+
export async function down(knex: Knex): Promise<void> {
10+
await knex.raw(`
11+
DROP INDEX CONCURRENTLY user_settings_user_id_tenant_id_idx;
12+
`);
13+
}
14+
15+
export const config = {
16+
transaction: false,
17+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type {Knex} from 'knex';
2+
3+
export async function up(knex: Knex): Promise<void> {
4+
await knex.raw(`
5+
ALTER TABLE user_settings DROP CONSTRAINT user_settings_pkey,
6+
ADD CONSTRAINT user_settings_сomposite_pkey
7+
PRIMARY KEY USING INDEX user_settings_user_id_tenant_id_idx;
8+
`);
9+
}
10+
11+
export async function down(knex: Knex): Promise<void> {
12+
await knex.raw(`
13+
ALTER TABLE user_settings DROP CONSTRAINT user_settings_сomposite_pkey,
14+
ADD CONSTRAINT user_settings_pkey PRIMARY KEY (user_id);
15+
16+
CREATE UNIQUE INDEX user_settings_user_id_tenant_id_idx ON user_settings (user_id, tenant_id);
17+
`);
18+
}

src/db/models/new/user-settings/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class UserSettings extends Model {
1010
}
1111

1212
userId!: string;
13+
tenantId!: string;
1314
settings!: Record<string, unknown>;
1415
updatedAt!: string;
1516
}

0 commit comments

Comments
 (0)