0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(schemas): set scope description to required (#2954)

This commit is contained in:
wangsijie 2023-01-17 18:04:49 +08:00 committed by GitHub
parent 2676561720
commit 92968c49dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View file

@ -40,7 +40,7 @@ describe('scopes', () => {
expect(scope).toBeTruthy();
const newScopeName = `new_${scope.name}`;
const newScopeDescription = `new_${scope.description ?? ''}`;
const newScopeDescription = `new_${scope.description}`;
const updatesScope = await updateScope(resource.id, scope.id, {
name: newScopeName,
@ -58,6 +58,7 @@ describe('scopes', () => {
const createdScope2 = await createScope(resource.id);
const response = await updateScope(resource.id, createdScope2.id, {
name: createdScope.name,
description: '',
}).catch((error: unknown) => error);
expect(response instanceof HTTPError && response.response.statusCode === 422).toBe(true);
});

View file

@ -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 scopes ALTER COLUMN description SET NOT NULL;
`);
},
down: async (pool) => {
await pool.query(sql`
ALTER TABLE scopes ALTER COLUMN description DROP NOT NULL;
`);
},
};
export default alteration;

View file

@ -2,7 +2,7 @@ create table scopes (
id varchar(21) not null,
resource_id varchar(21) not null references resources (id) on update cascade on delete cascade,
name varchar(256) not null,
description text,
description text not null,
created_at timestamptz not null default(now()),
primary key (id)
);