|Newbie questions about Pliant
Adding fields to db
Adding a field to a DB record
|Message posted by maybe Boris Reitman on 2006/09/22 22:04:56
|Hi, I would like to change my db objects.
Whats the best practice to do that ?
1) if I want to add a field
2) if I want to remove a field
|Message posted by hubert.tonneau on 2006/09/22 22:35:02
|I don't understand your question.
Maybe posting a tiny example would help.
|Message posted by maybe Boris Reitman on 2006/09/22 22:59:53
field Str sender_name
field Str unused_field
#field Str new_field
field Set:Order orders
(gvar Database:MyDatabase db) load "some_path/greenspace.pdb" mount "/some_path/greenspace
I have to get rid of "unused_field" and to add field "new_field",
while my database already has many records with field unused_field, but without
new_field. If I just change Order type by removing "field Str unused_field" and
by enabling "new_field", is anything going to break ? Or will new_field be empty
for old records as expected, and unused_field will be gone ?
|Message posted by hubert.tonneau on 2006/09/22 23:26:00
|You can safely add or remove fields. Restarting Pliant is enough.
This feature is the main reason for me not to add optimised writing (and so
optimised reading) of the database content (write a record as a consecutive
set of fields with no meta information in the middle). Having optimised writing
would require to write the type of each record in order to properly handle the
some new fields and some removed field case so it would make the all thing much
If you add:
field Str new_field <- "abc"
then in all existing records, the value of 'new_field' will be 'abc'
This might be more important with types such as 'Int' where there is no
default initial value as opposed to 'Str' where there is an implicit default
value, also there is nothing new here since the same applies for fields
that have been in the database right from the begining.