OpenUpSA/wazimap

FieldTable auto-creates the table, but SimpleTable doesn't

longhotsummer opened this issue · 3 comments

Declaring a FieldTable auto-creates the table in the database, but SimpleTable expects the table to exist and introspects it to get column data. They should behave the same way.

@longhotsummer

I would be happy to try my hand at addressing this issue. I am not familiar with how table creation through introspection works in Wazimap. Do you have any hints about where to start looking in the current code?

I suppose one concern is that SimpleTable does not take a fields parameter. Is the model parameter what is used for determining fields instead? And do you know of an example of someone using a model when declaring a SimpleTable?

Which do you think is better to do? Should we use the FieldTable behaviour that does the database work for you but requires your to explicitly list fields in the tables.py file? Or should we use the SimpleTable behaviour where it introspects the database, which means you need to do the database work?

I tend to think that Wazimap managing the database is easier, but I'd like to know what that was like for a new user.

I would vote for something that allows the declaration in tables.py to create the database table. As a new user, I appreciated the simplicity of the FieldTable behavior -- having Wazimap manage the database. I think having the SimpleTable behave similarly is advantageous. Then there is only one workflow.

Can this behavior be achieved with declaring a model in a SimpleTable? Is that what the model parameter is for? If so, I think that is sufficient and including information about how to do that in the documentation would be all that is needed.

For what it's worth, the documentation says Wazimap will create the table.

Adding a Simple Table

First, you must register your Simple Table in your project’s tables.py. When Wazimap starts, it will create the underlying database table if it doesn’t already exist.

I didn't see any documentation that stated that a SimpleTable required that the table already exist in the database.