#1 2010-11-26 18:09:04

ingoberg
Member
Registered: 2010-11-20
Posts: 17

modify table structure

How do I modify model / database? For example, how do I add a new field to a table?

Offline

#2 2010-11-26 18:38:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,549
Website

Re: modify table structure

Just add a published property to the class definition.
The column will be added to the table when the application starts.
It will call the corresponding TSQLRecord.InitializeTable method, with the field name, so that you could be able to initialize the table by itself according to this newly added field.

To delete or rename a column is not handled yet. Because we would need history, like in Ruby on Rails. I didn't find it very useful yet.

And... SQLite3 doesn't allow you to call ALTER TABLE in order to delete a column.
See http://www.sqlite.org/lang_altertable.html

But you can rename it.
It's better relying on the database version number, and write your own renaming code after calling TSQLRestServerDB.CreateMissingTables.

In all cases, see this method of SQLite3.pas to see how the database layout is synchronized.

Offline

Board footer

Powered by FluxBB