-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update JSON schema to specify that not all
Column
fields are requir…
…ed (#265) Update the JSON schema in `schema.json` to state that only `name` and `type` are required fields when specifying a column. Previously `required` was set to `["name", "nullable", "pk", "type", "unique"]` resulting in some valid `create_table` and `add_column` migrations failing to validate. Add two new testcases to the JSON schema tests to cover 'create_table' and 'add_column' operations.
- Loading branch information
1 parent
d00d804
commit d06a0af
Showing
25 changed files
with
303 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
This is a valid 'add_column' migration. | ||
Some optional column fields are specified and some aren't. | ||
|
||
-- create_table.json -- | ||
{ | ||
"name": "migration_name", | ||
"operations": [ | ||
{ | ||
"add_column": { | ||
"table": "reviews", | ||
"column": { | ||
"name": "rating", | ||
"type": "text", | ||
"default": "0" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
|
||
-- valid -- | ||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
This is a valid 'create_table' migration. | ||
Some optional column fields are specified and some aren't. | ||
|
||
-- create_table.json -- | ||
{ | ||
"name": "migration_name", | ||
"operations": [ | ||
{ | ||
"create_table": { | ||
"name": "posts", | ||
"columns": [ | ||
{ | ||
"name": "id", | ||
"type": "serial", | ||
"pk": true | ||
}, | ||
{ | ||
"name": "title", | ||
"type": "varchar(255)" | ||
}, | ||
{ | ||
"name": "user_id", | ||
"type": "integer", | ||
"nullable": true | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
|
||
-- valid -- | ||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package migrations | ||
|
||
func (c *Column) IsNullable() bool { | ||
if c.Nullable != nil { | ||
return *c.Nullable | ||
} | ||
return false | ||
} | ||
|
||
func (c *Column) IsUnique() bool { | ||
if c.Unique != nil { | ||
return *c.Unique | ||
} | ||
return false | ||
} | ||
|
||
func (c *Column) IsPrimaryKey() bool { | ||
if c.Pk != nil { | ||
return *c.Pk | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.