Updating the database
A initialized database is ready to be updated. Before updating, a version source must be created.
Learn more about Version sources
For this example we’ll use a very simple version source.
version_source = {
"engine": "postgres",
"name": "example-db",
"version": [{
"_id": "1.0.0",
"createtable": {
"customers": {
"primary_key": "customer_id",
"customer_id": {
"type": "INTEGER",
"generated": "BY DEFAULT"
},
"name": {
"type": "VARCHAR",
"length": 100,
"unique": True
},
"created": {
"type": "TIMESTAMP"
}
}
},
"default_data": {
"customers": [
{
"customer_id": 1,
"name": "John",
"created": "2023-10-31 02:12:52.000000"
},
{
"customer_id": 2,
"name": "Brian",
"created": "2022-02-21 11:42:19.000000"
},
{
"customer_id": 3,
"name": "Anouk",
"created": "2021-06-12 08:13:48.000000"
}
]
}
}]
}This will create the following table in your database:
| customer_id 🔑 | name | created |
|---|---|---|
| 1 | John | 2023-10-31 02:12:52.000000 |
| 2 | Brian | 2022-02-21 11:42:19.000000 |
| 3 | Anouk | 2021-06-12 08:13:48.000000 |
Using MySQL? Set
"engine"to"mysql"and use MySQL column types. See MySQL syntax.
Updating the table is as simple as just calling the update method. Make sure to supply the version source.
db.update(version_source=version_source)Last updated on