New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixtures app #229
Fixtures app #229
Conversation
Codecov Report
@@ Coverage Diff @@
## master #229 +/- ##
==========================================
- Coverage 90.50% 90.11% -0.40%
==========================================
Files 119 124 +5
Lines 5740 5916 +176
==========================================
+ Hits 5195 5331 +136
- Misses 545 585 +40
Continue to review full report at Codecov.
|
@sinisaos @aminalaee any thoughts on this change? In particular, moving Pydantic support into the main Piccolo repo. |
@dantownsend More or less all orm's (Tortoise, especially Ormar etc.) have a strong integration with Pydantic in their core. I think moving a serializers from Piccolo API to Piccolo ORM is a good idea that has more pros than cons. Unlike other libraries, the Piccolo API is specific because it allows you to easily create a web API-s, and I think there is no difference if we use Pydantic serialization from Piccolo ORM or from Piccolo API. |
I think that's ok. Pydantic is pretty stable now. My only concern is that there was a discussion that Python 3.10 will cause some issues with Pydantic, not sure how serious that is. |
@sinisaos @aminalaee Thanks for your input. There's a giant thread here about Pydantic and Python 3.10: pydantic/pydantic#2678 It seems like they've solved the issue (at least temporarily) 🤞 |
Adding a fixtures app which can be used to dump data from the database to a JSON file, and then reload it again.
To create a fixture:
piccolo fixture dump --apps=blog --tables=Post,PostComment > fixture.json
To load a fixture:
Reasons for adding it
Sharing data with colleagues
A Piccolo project can contain a fixture with all of the data a colleague needs to setup a project with. For example, if it's an app about selling cars, the fixture could contain all of the makes and models of cars.
Deploying to a new environment
When you want to deploy your application to production for the first time, you can load the fixture to populate the database with essential data.
Why not use pg_dump and pg_restore?
Whilst these are great tools, and achieve similar goals to fixtures, they're locked to a single Postgres version. With fixtures, you should be able to dump from say Postgres 12 and load into Postgres 13. This means you don't have to rebuild your fixtures when you update your Postgres version.
Also, having your fixtures in JSON is better for version control, and makes them easier to modify by hand.
Side effects
In order to implement this change, some fairly large changes had to be made to the wider codebase (though no breaking changes).
Test refactoring
The tests were refactored slightly - in the past there was a single example Piccolo app which the tests use (containing the
Band
,Manager
etc tables). There are now multiple example apps. The new one is calledmega
, and contains a table calledMegaTable
which has every column type, and is very useful for testing serialisation.Moving Pydantic into core
All of the Pydantic functionality is currently in Piccolo API. It was been discussed in the past about moving this into core (#10 (comment)).
The downside of doing so, is a tighter coupling to external dependencies. But on the other hand, it's so heavily used elsewhere in the Piccolo ecosystem, that practically it makes little difference.
So this PR moves the Pydantic code into the main Piccolo repo. In a future PR I'll remove the Pydantic code from Piccolo API, and will replace it with proxies to the code in Piccolo core.