Skip to content

Commit

Permalink
Update alter_column operation
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Rico <sferadev@gmail.com>
  • Loading branch information
SferaDev committed Feb 1, 2024
1 parent c770a98 commit 979d4d1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/pgroll/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Definition =
| {
type: 'object';
properties: Record<string, Definition>;
oneOf?: unknown[];
required?: string[];
description?: string;
additionalProperties?: boolean;
Expand All @@ -30,6 +31,8 @@ const DefinitionSchema: z.ZodSchema<Definition> = z.lazy(() =>
z.object({
type: z.literal('object'),
properties: z.record(DefinitionSchema),
// TODO: Add full support for oneOf
oneOf: z.array(z.any()).optional(),
required: z.array(z.string()).optional(),
description: z.string().optional(),
additionalProperties: z.boolean().optional()
Expand Down Expand Up @@ -146,7 +149,8 @@ function topologicalSort(nodes: [string, Definition][]): [string, Definition][]
}

async function main() {
const response = await fetch(PGROLL_JSON_SCHEMA_URL).then((response) => response.json());
const url = process.env.PGROLL_JSON_SCHEMA_URL ?? PGROLL_JSON_SCHEMA_URL;
const response = await fetch(url).then((response) => response.json());
const schema = JSONSchema.parse(response);

// Create a TypeScript project
Expand Down
33 changes: 32 additions & 1 deletion packages/pgroll/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,38 @@ export const schema = {
type: 'string'
}
},
required: ['column', 'down', 'name', 'table', 'type', 'up'],
required: ['table', 'column'],
oneOf: [
{
required: ['name'],
not: {
required: ['up', 'down']
}
},
{
required: ['up', 'down'],
oneOf: [
{
required: ['check']
},
{
required: ['type']
},
{
required: ['nullable']
},
{
required: ['unique']
},
{
required: ['references']
}
],
not: {
required: ['name']
}
}
],
type: 'object'
},
OpCreateIndex: {
Expand Down
8 changes: 4 additions & 4 deletions packages/pgroll/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export type OpAlterColumn = z.infer<typeof OpAlterColumnDefinition>;
export const OpAlterColumnDefinition = z.object({
check: CheckConstraintDefinition.optional(),
column: z.string(),
down: z.string(),
name: z.string(),
down: z.string().optional(),
name: z.string().optional(),
nullable: z.boolean().optional(),
references: ForeignKeyReferenceDefinition.optional(),
table: z.string(),
type: z.string(),
type: z.string().optional(),
unique: UniqueConstraintDefinition.optional(),
up: z.string()
up: z.string().optional()
});

export type OpCreateIndex = z.infer<typeof OpCreateIndexDefinition>;
Expand Down

0 comments on commit 979d4d1

Please sign in to comment.