how to add tables to databes on plugin installation

5 views
Skip to first unread message

Markus Rosjat

unread,
Jan 28, 2023, 4:12:11 PM1/28/23
to trac-...@googlegroups.com
hi list,

is there any kind of "sane" example how to archive this task?  the upgrade section for the database
is, at least for a dummy like me, not in the slidest useful. 

the update section in TracDev desnt help at all since you can'T get behind the magic that would give you a pointer to a "fresh" creation of a table for a plugin.

a example with the necessary steps in the IEnvironmentSetupParticipant functions
would help a lot.

cheers

MArkus

Jun Omae

unread,
Jan 29, 2023, 12:55:11 AM1/29/23
to trac-...@googlegroups.com

Markus Rosjat

unread,
Jan 29, 2023, 3:33:42 AM1/29/23
to trac-...@googlegroups.com
hey jun,

yeah i do look at examples, problem for me was it never really triggered the upgrade so i spend yesterday getting something to work. I have now something that looks like the example in general but with a lot of hacky 
stuff from other plugins like TagsTrac. So i will try to clean up my code to a version that works in a "cleaner" way i guess.

Cheers 

MArkus

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/CAEVLMag7Cjvy6Xf2Xo3TnpbZrg0DJdq0JogK1iS5vMt4Y1bfQw%40mail.gmail.com.

Markus Rosjat

unread,
Jan 29, 2023, 3:52:27 AM1/29/23
to trac-...@googlegroups.com
btw I see a lot of Table definitions and i figure the key is like the primary key for the table but does trac implementation of table and column has the concept of a foreign key or is this something we need to check in the code ?

for example the ticket tables, ticket table has an id and related table have a column ticket that seems to be the ref to the tickek id but i dont see any definition of a foreign key so i there seems to be no integrity checks? This in turn defeats the
whole purpose of a releational database.

cheers

Markus

Markus Rosjat

unread,
Jan 29, 2023, 6:26:53 AM1/29/23
to trac-...@googlegroups.com
another strange behaviour, at least in my opinion, is that if i define a column to be auto_increment i expect the insert statements to take care of the incrementation of the column if i omit it,

for example I define a table 

    Table("ttmsd_webhook_types", key=("id"))[
                Column("id", type="int",auto_increment=True),
                Column("name", type="text"),],

then I expect to pass data to insert_into_table to work with a tuple like

("ttmsd_webhook_types",
            ("name"),
                (("MS Teams",),
                ("Discord",))
 )
but it doesnt, it give me a IndexError: tuple index out of range error and i need to define my tuple like

("ttmsd_webhook_types",
            ("id","name"),
                ((1,"MS Teams",),
                (2,"Discord",))
        )
for initial data that should be fine since i know what i add but if i want to update my types later on I always need to get the count of the id sequence first to not mess up.

Or do I simply miss stuff here ???

Cheers

MArkus

Jun Omae

unread,
Jan 29, 2023, 6:40:25 AM1/29/23
to trac-...@googlegroups.com
On Sun, Jan 29, 2023 at 8:26 PM Markus Rosjat <markus...@gmail.com> wrote:
> then I expect to pass data to insert_into_table to work with a tuple like
>
> ("ttmsd_webhook_types",
> ("name"),
> (("MS Teams",),
> ("Discord",))
> )

The columns should be a list or a tuple.

- ("name"),
+ ["name"],

> for initial data that should be fine since i know what i add but if i want to update my types later on I always need to get the count of the id sequence first to not mess up.

If you need other operations than simple inserting rows, use directly
queries such SELECT/INSERT/UPDATE/DELETE using
self.env.db_transaction() and cursor.execute().

Markus Rosjat

unread,
Jan 29, 2023, 7:25:30 AM1/29/23
to trac-...@googlegroups.com
i will try that and i saw the plain sql string approach too but i got some basic stuff working at the moment.

cheers

Markus

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages