pip-services3-go / pip-services3-postgres-go

Postresql components for Pip.Services in Golang
MIT License
0 stars 0 forks source link

EnsureSchema not executing scripts after the first time execution #2

Closed dthomas26 closed 3 years ago

dthomas26 commented 3 years ago

I am noticing if I create a table using something like this

    c.EnsureSchema("CREATE TABLE " + c.QuoteTableNameWithSchema() + " (\"id\" bigint NOT NULL, \"xyz\" TEXT ,\"abc\" bigint,  CONSTRAINT table_pkey PRIMARY KEY (id));")

and now if I start the service table get's created. Now, I am adding an additional constraint or index to the table using EnsureSchema and re-run the microservice it never get's executed. Is this behaviour expected? Any changes to the table schema wrt to constraint/index's can-not be added after the first execution?

seroukhov commented 3 years ago

That is correct. The persistence component doesn't have logic to analyze statements and decide which one shall be executed or how it shall be altered. It simply uses the presence of the table as an indicator to create an initial set of objects. Altering an existing database is a whole different story. It is a non-trivial task and sometimes it may take hours to convert objects in a large production database. So, the recommended way is to deal with altering the database separately and before launching a microservice.