diff --git a/pkg/migrations/types.go b/pkg/migrations/types.go index 72da7b90..af88181a 100644 --- a/pkg/migrations/types.go +++ b/pkg/migrations/types.go @@ -3,101 +3,103 @@ package migrations type CheckConstraint struct { - // Constraint corresponds to the JSON schema field "constraint". + // Constraint expression Constraint string `json:"constraint"` - // Name corresponds to the JSON schema field "name". + // Name of check constraint Name string `json:"name"` } +// Column definition type Column struct { - // Check corresponds to the JSON schema field "check". + // Check constraint for the column Check *CheckConstraint `json:"check,omitempty"` - // Default corresponds to the JSON schema field "default". + // Default value for the column Default *string `json:"default,omitempty"` - // Name corresponds to the JSON schema field "name". + // Name of the column Name string `json:"name"` - // Nullable corresponds to the JSON schema field "nullable". + // Indicates if the column is nullable Nullable bool `json:"nullable"` - // Pk corresponds to the JSON schema field "pk". + // Indicates if the column is part of the primary key Pk bool `json:"pk"` - // References corresponds to the JSON schema field "references". + // Foreign key constraint for the column References *ForeignKeyReference `json:"references,omitempty"` - // Type corresponds to the JSON schema field "type". + // Postgres type of the column Type string `json:"type"` - // Unique corresponds to the JSON schema field "unique". + // Indicates if the column values must be unique Unique bool `json:"unique"` } type ForeignKeyReference struct { - // Column corresponds to the JSON schema field "column". + // Name of the referenced column Column string `json:"column"` - // Name corresponds to the JSON schema field "name". + // Name of the foreign key constraint Name string `json:"name"` - // Table corresponds to the JSON schema field "table". + // Name of the referenced table Table string `json:"table"` } type OpAddColumn struct { - // Column corresponds to the JSON schema field "column". + // Column to add Column Column `json:"column"` - // Table corresponds to the JSON schema field "table". + // Name of the table Table string `json:"table"` - // Up corresponds to the JSON schema field "up". + // SQL expression for up migration Up *string `json:"up,omitempty"` } type OpAlterColumn struct { - // Check corresponds to the JSON schema field "check". + // Add check constraint to the column Check *CheckConstraint `json:"check,omitempty"` - // Column corresponds to the JSON schema field "column". + // Name of the column Column string `json:"column"` - // Down corresponds to the JSON schema field "down". + // SQL expression for down migration Down string `json:"down"` - // Name corresponds to the JSON schema field "name". + // New name of the column (for rename column operation) Name string `json:"name"` - // Nullable corresponds to the JSON schema field "nullable". + // Indicates if the column is nullable (for add not null constraint operation) Nullable *bool `json:"nullable,omitempty"` - // References corresponds to the JSON schema field "references". + // Add foreign key constraint to the column References *ForeignKeyReference `json:"references,omitempty"` - // Table corresponds to the JSON schema field "table". + // Name of the table Table string `json:"table"` - // Type corresponds to the JSON schema field "type". + // New type of the column (for change type operation) Type string `json:"type"` - // Unique corresponds to the JSON schema field "unique". + // Add unique constraint to the column Unique *UniqueConstraint `json:"unique,omitempty"` - // Up corresponds to the JSON schema field "up". + // SQL expression for up migration Up string `json:"up"` } +// Create index operation type OpCreateIndex struct { - // Columns corresponds to the JSON schema field "columns". + // Names of columns on which to define the index Columns []string `json:"columns"` - // Name corresponds to the JSON schema field "name". + // Index name Name string `json:"name"` - // Table corresponds to the JSON schema field "table". + // Name of table on which to define the index Table string `json:"table"` } @@ -105,74 +107,74 @@ type OpCreateTable struct { // Columns corresponds to the JSON schema field "columns". Columns []Column `json:"columns"` - // Name corresponds to the JSON schema field "name". + // Name of the table Name string `json:"name"` } type OpDropColumn struct { - // Column corresponds to the JSON schema field "column". + // Name of the column Column string `json:"column"` - // Down corresponds to the JSON schema field "down". + // SQL expression for down migration Down *string `json:"down,omitempty"` - // Table corresponds to the JSON schema field "table". + // Name of the table Table string `json:"table"` } type OpDropConstraint struct { - // Column corresponds to the JSON schema field "column". + // Name of the column Column string `json:"column"` - // Down corresponds to the JSON schema field "down". + // SQL expression for down migration Down string `json:"down"` - // Name corresponds to the JSON schema field "name". + // Name of the constraint Name string `json:"name"` - // Table corresponds to the JSON schema field "table". + // Name of the table Table string `json:"table"` - // Up corresponds to the JSON schema field "up". + // SQL expression for up migration Up string `json:"up"` } type OpDropIndex struct { - // Name corresponds to the JSON schema field "name". + // Index name Name string `json:"name"` } type OpDropTable struct { - // Name corresponds to the JSON schema field "name". + // Name of the table Name string `json:"name"` } type OpRawSQL struct { - // Down corresponds to the JSON schema field "down". + // SQL expression for down migration Down string `json:"down,omitempty"` - // Up corresponds to the JSON schema field "up". + // SQL expression for up migration Up string `json:"up"` } type OpRenameTable struct { - // From corresponds to the JSON schema field "from". + // Old name of the table From string `json:"from"` - // To corresponds to the JSON schema field "to". + // New name of the table To string `json:"to"` } type OpSetReplicaIdentity struct { - // Identity corresponds to the JSON schema field "identity". + // Replica identity to set Identity ReplicaIdentity `json:"identity"` - // Table corresponds to the JSON schema field "table". + // Name of the table Table string `json:"table"` } type PgRollMigration struct { - // Name corresponds to the JSON schema field "name". + // Name of the migration Name string `json:"name"` // Operations corresponds to the JSON schema field "operations". @@ -180,14 +182,14 @@ type PgRollMigration struct { } type ReplicaIdentity struct { - // Index corresponds to the JSON schema field "Index". + // Name of the index to use as replica identity Index string `json:"Index"` - // Type corresponds to the JSON schema field "Type". + // Type of replica identity Type string `json:"Type"` } type UniqueConstraint struct { - // Name corresponds to the JSON schema field "name". + // Name of unique constraint Name string `json:"name"` } diff --git a/schema.json b/schema.json index 064785b6..30b7f2ca 100644 --- a/schema.json +++ b/schema.json @@ -6,40 +6,51 @@ "additionalProperties": false, "properties": { "constraint": { - "type": "string" + "type": "string", + "description": "Constraint expression" }, "name": { - "type": "string" + "type": "string", + "description": "Name of check constraint" } }, "required": ["constraint", "name"], "type": "object" }, "Column": { + "description": "Column definition", "properties": { "check": { - "$ref": "#/definitions/CheckConstraint" + "$ref": "#/definitions/CheckConstraint", + "description": "Check constraint for the column" }, "default": { - "type": "string" + "type": "string", + "description": "Default value for the column" }, "name": { - "type": "string" + "type": "string", + "description": "Name of the column" }, "nullable": { - "type": "boolean" + "type": "boolean", + "description": "Indicates if the column is nullable" }, "pk": { - "type": "boolean" + "type": "boolean", + "description": "Indicates if the column is part of the primary key" }, "references": { - "$ref": "#/definitions/ForeignKeyReference" + "$ref": "#/definitions/ForeignKeyReference", + "description": "Foreign key constraint for the column" }, "type": { - "type": "string" + "type": "string", + "description": "Postgres type of the column" }, "unique": { - "type": "boolean" + "type": "boolean", + "description": "Indicates if the column values must be unique" } }, "required": ["name", "nullable", "pk", "type", "unique"], @@ -49,13 +60,16 @@ "additionalProperties": false, "properties": { "column": { - "type": "string" + "type": "string", + "description": "Name of the referenced column" }, "name": { - "type": "string" + "type": "string", + "description": "Name of the foreign key constraint" }, "table": { - "type": "string" + "type": "string", + "description": "Name of the referenced table" } }, "required": ["column", "name", "table"], @@ -65,13 +79,16 @@ "additionalProperties": false, "properties": { "column": { - "$ref": "#/definitions/Column" + "$ref": "#/definitions/Column", + "description": "Column to add" }, "table": { - "type": "string" + "type": "string", + "description": "Name of the table" }, "up": { - "type": "string" + "type": "string", + "description": "SQL expression for up migration" } }, "required": ["column", "table"], @@ -81,34 +98,44 @@ "additionalProperties": false, "properties": { "check": { - "$ref": "#/definitions/CheckConstraint" + "$ref": "#/definitions/CheckConstraint", + "description": "Add check constraint to the column" }, "column": { - "type": "string" + "type": "string", + "description": "Name of the column" }, "down": { - "type": "string" + "type": "string", + "description": "SQL expression for down migration" }, "name": { - "type": "string" + "type": "string", + "description": "New name of the column (for rename column operation)" }, "nullable": { - "type": "boolean" + "type": "boolean", + "description": "Indicates if the column is nullable (for add not null constraint operation)" }, "references": { - "$ref": "#/definitions/ForeignKeyReference" + "$ref": "#/definitions/ForeignKeyReference", + "description": "Add foreign key constraint to the column" }, "table": { - "type": "string" + "type": "string", + "description": "Name of the table" }, "type": { - "type": "string" + "type": "string", + "description": "New type of the column (for change type operation)" }, "unique": { - "$ref": "#/definitions/UniqueConstraint" + "$ref": "#/definitions/UniqueConstraint", + "description": "Add unique constraint to the column" }, "up": { - "type": "string" + "type": "string", + "description": "SQL expression for up migration" } }, "required": ["column", "down", "name", "table", "type", "up"], @@ -121,29 +148,35 @@ "items": { "type": "string" }, - "type": "array" + "type": "array", + "description": "Names of columns on which to define the index" }, "name": { - "type": "string" + "type": "string", + "description": "Index name" }, "table": { - "type": "string" + "type": "string", + "description": "Name of table on which to define the index" } }, "required": ["columns", "name", "table"], - "type": "object" + "type": "object", + "description": "Create index operation" }, "OpCreateTable": { "additionalProperties": false, "properties": { "columns": { "items": { - "$ref": "#/definitions/Column" + "$ref": "#/definitions/Column", + "description": "Columns to add to the table" }, "type": "array" }, "name": { - "type": "string" + "type": "string", + "description": "Name of the table" } }, "required": ["columns", "name"], @@ -153,13 +186,16 @@ "additionalProperties": false, "properties": { "column": { - "type": "string" + "type": "string", + "description": "Name of the column" }, "down": { - "type": "string" + "type": "string", + "description": "SQL expression for down migration" }, "table": { - "type": "string" + "type": "string", + "description": "Name of the table" } }, "required": ["column", "table"], @@ -169,19 +205,24 @@ "additionalProperties": false, "properties": { "column": { - "type": "string" + "type": "string", + "description": "Name of the column" }, "down": { - "type": "string" + "type": "string", + "description": "SQL expression for down migration" }, "name": { - "type": "string" + "type": "string", + "description": "Name of the constraint" }, "table": { - "type": "string" + "type": "string", + "description": "Name of the table" }, "up": { - "type": "string" + "type": "string", + "description": "SQL expression for up migration" } }, "required": ["column", "down", "name", "table", "up"], @@ -191,7 +232,8 @@ "additionalProperties": false, "properties": { "name": { - "type": "string" + "type": "string", + "description": "Index name" } }, "required": ["name"], @@ -201,7 +243,8 @@ "additionalProperties": false, "properties": { "name": { - "type": "string" + "type": "string", + "description": "Name of the table" } }, "required": ["name"], @@ -212,10 +255,12 @@ "properties": { "down": { "default": "", - "type": "string" + "type": "string", + "description": "SQL expression for down migration" }, "up": { - "type": "string" + "type": "string", + "description": "SQL expression for up migration" } }, "required": ["up"], @@ -225,10 +270,12 @@ "additionalProperties": false, "properties": { "from": { - "type": "string" + "type": "string", + "description": "Old name of the table" }, "to": { - "type": "string" + "type": "string", + "description": "New name of the table" } }, "required": ["from", "to"], @@ -238,10 +285,12 @@ "additionalProperties": false, "properties": { "identity": { - "$ref": "#/definitions/ReplicaIdentity" + "$ref": "#/definitions/ReplicaIdentity", + "description": "Replica identity to set" }, "table": { - "type": "string" + "type": "string", + "description": "Name of the table" } }, "required": ["identity", "table"], @@ -251,43 +300,55 @@ "additionalProperties": false, "properties": { "name": { - "type": "string" + "type": "string", + "description": "Name of the migration" }, "operations": { "items": { "anyOf": [ { - "$ref": "#/definitions/OpAddColumn" + "$ref": "#/definitions/OpAddColumn", + "description": "Add column operation" }, { - "$ref": "#/definitions/OpAlterColumn" + "$ref": "#/definitions/OpAlterColumn", + "description": "Alter column operation" }, { - "$ref": "#/definitions/OpCreateIndex" + "$ref": "#/definitions/OpCreateIndex", + "description": "Create index operation" }, { - "$ref": "#/definitions/OpCreateTable" + "$ref": "#/definitions/OpCreateTable", + "description": "Create table operation" }, { - "$ref": "#/definitions/OpDropColumn" + "$ref": "#/definitions/OpDropColumn", + "description": "Drop column operation" }, { - "$ref": "#/definitions/OpDropConstraint" + "$ref": "#/definitions/OpDropConstraint", + "description": "Drop constraint operation" }, { - "$ref": "#/definitions/OpDropIndex" + "$ref": "#/definitions/OpDropIndex", + "description": "Drop index operation" }, { - "$ref": "#/definitions/OpDropTable" + "$ref": "#/definitions/OpDropTable", + "description": "Drop table operation" }, { - "$ref": "#/definitions/OpRawSQL" + "$ref": "#/definitions/OpRawSQL", + "description": "Raw SQL operation" }, { - "$ref": "#/definitions/OpRenameTable" + "$ref": "#/definitions/OpRenameTable", + "description": "Rename table operation" }, { - "$ref": "#/definitions/OpSetReplicaIdentity" + "$ref": "#/definitions/OpSetReplicaIdentity", + "description": "Set replica identity operation" } ] }, @@ -301,10 +362,12 @@ "additionalProperties": false, "properties": { "Index": { - "type": "string" + "type": "string", + "description": "Name of the index to use as replica identity" }, "Type": { - "type": "string" + "type": "string", + "description": "Type of replica identity" } }, "required": ["Index", "Type"], @@ -314,7 +377,8 @@ "additionalProperties": false, "properties": { "name": { - "type": "string" + "type": "string", + "description": "Name of unique constraint" } }, "required": ["name"],