Schema generation enhancements
See original GitHub issuePiccolo now has a command for generating a schema from an existing database.
piccolo schema generate
The current implementation doesn’t cover every possible edge case and database feature, so there’s room for improvement. For example:
Column defaults
Getting the defaults for a column, and reflecting them in the Piccolo column. For example, if the column has a default of 1
in the database, we want that to be reflected in the Piccolo schema as:
class MyTable(Table):
my_column = Integer(default=1)
On Delete / On Update
The database values aren’t currently reflected in the ForeignKey
column definitions.
class MyTable(Table):
my_column = ForeignKey(on_delete=OnDelete.cascade)
Decimal precision
The precision of a decimal column in the database currently isn’t reflected in the Decimal
column definitions.
class MyTable(Table):
my_column = Decimal(digits=(5,2))
It’s a fairly beginner friendly feature to work on, because even though the code is fairly advanced, it’s completely self contained, and doesn’t require extensive knowledge of the rest of Piccolo.
Issue Analytics
- State:
- Created 2 years ago
- Comments:24 (24 by maintainers)
@wmshort Yeah, it was just omitted because we didn’t have the reflection capabilities at the time.
@wmshort Good question - it looks like you can find
ON DELETE
andON UPDATE
here:I found this gist on it:
https://gist.github.com/velosipedist/7250141