Comments (9)
The default for a Timestamp
column is this (from here):
class TimestampNow(Default):
@property
def postgres(self):
return "current_timestamp"
@property
def sqlite(self):
return "current_timestamp"
def python(self):
return datetime.datetime.now()
You can see that we use current_timestamp
. What we should probably have instead is current_timestamp::timestamp
, as current_timestamp
includes the timezone.
It seems like CockroachDB is slightly stricter than Postgres, because Postgres allows this (it must automatically do some type conversion).
So it's something we can fix in Piccolo.
In the mean time I can push a fix to the piccolo_examples
repo, so it uses a Timestamptz
column instead of Timestamp
, which should work OK with CockroachDB if you like.
from piccolo_api.
Here's the changeset that worked for me. No changes to headless_blog_fastapi
.
https://github.com/piccolo-orm/piccolo/blob/master/piccolo/columns/defaults/timestamp.py
Line 24: return f"CURRENT_TIMESTAMP::timestamp + INTERVAL '{interval_string}'"
Line 45: return "current_timestamp::timestamp"
All good:
gnat@gnat:~/Desktop/headless_blog_fastapi$ piccolo migrations forwards all --trace
BLOG
----------------------------------------------------------------
👍 0 migrations already complete
🏁 No migrations need to be run
SESSION_AUTH
----------------------------------------------------------------
👍 1 migration already complete
⏩ 1 migration not yet run
🚀 Running 1 migration:
- 2019-11-12T20:47:17 [forwards]... ok! ✔️
USER
----------------------------------------------------------------
👍 3 migrations already complete
⏩ 3 migrations not yet run
🚀 Running 3 migrations:
- 2019-11-14T21:52:21 [forwards]... ok! ✔️
- 2020-06-11T21:38:55 [forwards]... ok! ✔️
- 2021-04-30T16:14:15 [forwards]... ok! ✔️
PICCOLO_ADMIN
----------------------------------------------------------------
👍 0 migrations already complete
🏁 No migrations need to be run
gnat@gnat:~/Desktop/headless_blog_fastapi$
from piccolo_api.
piccolo-admin running under Cockroach DB.
from piccolo_api.
Yup, thank you! @sinisaos
from piccolo_api.
Thanks for the quick reply! @dantownsend You rock!
In the mean time I can push a fix to the piccolo_examples repo, so it uses a Timestamptz column instead of Timestamp, which should work OK with CockroachDB if you like.
Might as well if it's not to big of a deal. Every little bit helps to get closer to friction-free Cockroach DB support. Cockroach Labs really needs to be promoting an async ORM and I'd love it to be piccolo.
from piccolo_api.
I've updated the piccolo_examples
repo. If you pull the latest, and try running the migration, hopefully it'll work.
Might as well if it's not to big of a deal. Every little bit helps to get closer to friction-free Cockroach DB support. Cockroach Labs really needs to be promoting an async ORM and I'd love it to be piccolo.
Yeah, I really need to dig into CockroachDB more - it should really have first class support from Piccolo. The first step is getting the tests / CI running with it.
from piccolo_api.
Btw, here's a quickstart if you wanted to run some tests for yourself:
- Download/extract (single binary): https://binaries.cockroachdb.com/cockroach-v22.1.6.linux-amd64.tgz
- Start Cockroach:
./cockroach start-single-node --insecure --store=node1 --listen-addr=localhost:26257 --http-addr=localhost:8080 --background
- Enter SQL client:
./cockroach sql --insecure
- Can
create database ...;
use ...;
from here.
- Can
- CTRL-C or
killall cockroach
to send graceful termination signal.
Default account is root
without password. Fancy stats dashboard at http://localhost:8080
It's pretty much the easiest database to set up. 😉
from piccolo_api.
@gnat This is great. Thanks
from piccolo_api.
@gnat Can you please close this issue as you have already done all the work in the main Piccolo ORM repo. Thanks.
from piccolo_api.
Related Issues (20)
- Feature to modify body and query_parameters in `PiccoloCRUD` HOT 8
- Fix code scanning alert - Unused global variable
- Batch version of the get endpoint HOT 6
- Drop Python 3.7 support
- Catch foreign key constraint errors in `PiccoloCRUD`
- `schema_extra` param not passed to `pydantic_model_{output | optional | plural}` methods HOT 1
- Piccolo Admin API docs are not rendering
- Better error display on PATCH request
- Alpha version for Pydantic 2.0 / Piccolo 1.0a1? HOT 2
- PiccoloCRUD `post_single` return id of the inserted row instead of the row HOT 3
- Add `ne` operator
- Python 3.12 support
- RateLimitingMiddleware tests failed HOT 5
- Stop multi-dimensional arrays from breaking
- Issue with updating and bulk updating `BaseUser` via admin panel HOT 15
- Updating middleware syntax HOT 6
- Make `default-src` configurable in `CSPMiddleware`
- Hide parameter in Validators to hide Piccolo Admin table link from sidebar if the validators fail. HOT 8
- Add `excluded_paths` to `SessionsAuthBackend`
- Replace deprecated `abstractproperty`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from piccolo_api.