Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

NOT NULL on uuid columns (Sideeffects and possible defect) #97

Open
toirl opened this issue Sep 21, 2017 · 2 comments
Open

NOT NULL on uuid columns (Sideeffects and possible defect) #97

toirl opened this issue Sep 21, 2017 · 2 comments

Comments

@toirl
Copy link
Member

toirl commented Sep 21, 2017

Commit b04ef3f of PR #87 by @g-tom introcduced a not null constraint on uuid column of all tables. This is generally an improvement to enforce a value. Unfortunately this introduces the problem that it is not possible anymore to write INSERT statements to insert data into the database without generating a new UUID before. This wasn't considered beeing a problem during the review of the PR, including myself.

This problem affects at least the migrations. I expect some of the ringo-admin commands will also have issues with this (e.g add modul, which inserts new entries in the modul table), but I did not have tested this so far.

At least for the migrations a workaround might be to generate some uuid on the python shell and use those UUID in the migrations:

import uuid
for u in range(10):
    str(uuid.uuid4())

However. It would be nice if we can make the DB autogenerate a UUID in case it is missing.

@g-tom
Copy link

g-tom commented Sep 21, 2017

Unfortunately this introduces the problem that it is not possible anymore to write INSERT statements to insert data into the database without generating a new UUID before.

This is correct in case the statement is not generated by the ORM. Otherwise the default already solves the problem:

ringo/ringo/model/base.py

Lines 145 to 148 in 2f84645

uuid = Column('uuid', CHAR(36),
unique=True,
nullable=False,
default=lambda x: str(uuid.uuid4()))

It would be nice if we can make the DB autogenerate a UUID in case it is missing.

You can have a look at the implementation in AGrav (unfortunately not publicly available), if you really need the UUIDs generated by the database. It's based on pgcrypto:
https://www.postgresql.org/docs/10/static/pgcrypto.html#idm45262034210592

@g-tom
Copy link

g-tom commented Sep 25, 2017

Because of the title here: see also #98

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants