You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by Daniel Augusto Veronezi Salvador <dv...@gmail.com> on 2023/02/07 00:43:36 UTC

[DISCUSSION] Management of the database's "VIEW"s

Hello guys,

I would like to open a discussion on our current management of the database's "VIEW"s.

Currently, we have to look at the changes in the previous "schema" files and replicate the whole "CREATE VIEW" command in the current "schema" file, modifying what we need (adding/removing columns, and so on). This process makes the changes in a "VIEW" to be distributed through several files, increasing the number of lines modified for simple changes (e.g.: for adding a single field to the "VIEW" result we need to replicate the whole command); thus, making it difficult to maintain and track.

With that in mind, I had some ideas of how we can improve this process. The proposal is: instead of adding the changes to the current "schema" file, we create unique files for each "VIEW" and manage them; more detailed:
1. under the directory "db", where the "schema" files are, we would create a sub-directory called "views";
2. in the sub-directory "views", we would create a file for each "VIEW", named with the "VIEW" name (for instance, "cloud.network_offering_view.sql");
3. in the "VIEW" file, we would put the "DROP VIEW" command, followed by the "CREATE VIEW" command, just as we do in the "schema" file; for instance, the content of file "cloud.network_offering_view.sql" would be:

```
DROP VIEW IF EXISTS `cloud`.`network_offering_view`;

CREATE VIEW `cloud`.`network_offering_view` AS
     SELECT
         `network_offerings`.`id` AS `id`,
         `network_offerings`.`uuid` AS `uuid`,
         `network_offerings`.`name` AS `name`,
     <the rest of the CREATE VIEW command>
```

4. then, after each version upgrade, in Java we execute all the files in the sub-directory "views"; this way, if a "VIEW" changed, it would be recreated with the new changes; otherwise, it would be only recreated as is;

That would allow us to easily track "VIEW" modifications, as we would just change the "VIEW" declaration in the same file, instead of re-declaring the whole "VIEW" in a different file; and we would have a better history of the changes. Also, we would not need to migrate all "VIEW"s right away; we could migrate as we change them.

Please, let me know your thoughts about the proposal.

Best regards,
Daniel Salvador (gutoveronezi)

Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Daniel Salvador <gu...@apache.org>.
Hello guys,

Sorry for the delay; I created PR 7417 [¹] to address the discussion we had
in this thread.

Best regards,
Daniel Salvador (gutoveronezi)

[¹] https://github.com/apache/cloudstack/pull/7417


On Tue, Feb 14, 2023 at 10:37 AM Wei ZHOU <us...@gmail.com> wrote:

> Agree with Daan.  go for it @Daniel
>
> One problem that needs to be solved is, there are few SQL upgrade scripts
> that rely on views. You can check by command
>
> git grep "_view" engine/schema/src/main/ |egrep -v -i 'DROP VIEW|CREATE
> VIEW'
>
> Kind regards,
> Wei
>
>
>
>
>
>
>
> On Tue, 14 Feb 2023 at 14:27, Daan Hoogland <da...@gmail.com>
> wrote:
>
> > Daniel, I think this is a lazy consensus issue and any further discussion
> > can happen on a PR. No vote thread needed.
> >
> > On Mon, Feb 13, 2023 at 10:45 PM Daniel Salvador <
> gutoveronezi@apache.org>
> > wrote:
> >
> > > I think I messed up with the format of my last email. Here follows the
> > > message in the correct format:
> > >
> > > ---
> > >
> > > Thank you for the replies, guys.
> > >
> > > I agree using frameworks (ORM and/or OOQ) might facilitate CloudStack's
> > > developers' life. Given the complexity of the project and the whole
> > > analysis and discussion necessary, it would require a lot of effort and
> > > time to implement it, as Daan mentioned; we could open a new discussion
> > on
> > > this topic later.
> > >
> > > Regarding the enforcement, we could validate it via GitHub actions, as
> > > Rohit suggested; and add the instructions in our Coding Convention on
> > > Confluence[¹] as well.
> > >
> > > About Wei's suggestion on having all views in a single file, in my
> > opinion,
> > > having a separate file for each "VIEW" rather than all in a single file
> > > would be more organized and facilitate the diff checking and change
> > > tracking, but we can better discuss the pros and cons of each approach.
> > >
> > > ---
> > >
> > > Summarizing what we discussed so far, to improve the database's "VIEW"s
> > > management, we can have two phases: in the first phase, we manage the
> > > "VIEW"s via specific files (or all "VIEW"s in a single file), executing
> > > them after each version upgrade; in a second phase, we could add a
> > > framework to ACS to improve the whole database management.
> > >
> > > Should I open a vote thread for the proposal of the first phase or can
> I
> > > already open a PR with the POC and we discuss the details there?
> > >
> > > ---
> > >
> > > Best regards,
> > > Daniel Salvador (gutoveronezi)
> > >
> > > [¹]:
> > >
> >
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Coding+conventions
> > >
> > > On Mon, Feb 13, 2023 at 6:37 PM Daniel Salvador <
> gutoveronezi@apache.org
> > >
> > > wrote:
> > >
> > > > Thank you for the replies, guys.
> > > >>
> > > >> I agree using frameworks (ORM and/or OOQ) might facilitate
> > CloudStack's
> > > >> developers' life. Given the complexity of the project and the whole
> > > >> analysis and discussion necessary, it would require a lot of effort
> > and
> > > >> time to implement it, as Daan mentioned; we could open a new
> > discussion
> > > on
> > > >> this topic later.
> > > >>
> > > >> Regarding the enforcement, we could validate it via GitHub actions,
> as
> > > >> Rohit suggested; and add the instructions in our Coding Convention
> on
> > > >> Confluence[¹] as well.
> > > >>
> > > >> About Wei's suggestion on having all views in a single file, in my
> > > >> opinion, having a separate file for each "VIEW" rather than all in a
> > > single
> > > >> file would be more organized and facilitate the diff checking and
> > change
> > > >> tracking, but we can discuss better the pros and cons of each
> > approach.
> > > >>
> > > >> ---
> > > >>
> > > >> Summarizing what we discussed so far, to improve the database's
> > "VIEW"s
> > > >> management, we can have two phases: in the first phase, we manage
> the
> > > >> "VIEW"s via specific files (or all "VIEW"s in a single file),
> > executing
> > > >> them after each version upgrade; in a second phase, we could add a
> > > >> framework to ACS to improve the whole database management.
> > > >>
> > > >> Should I open a vote thread for the proposal of the first phase or
> > can I
> > > >> already open a PR with the POC and we discuss the details there?
> > > >>
> > > >> ---
> > > >>
> > > >> Best regards,
> > > >> Daniel Salvador (gutoveronezi)
> > > >>
> > > >> [¹]:
> > > >>
> > >
> >
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Coding+conventions
> > > >>
> > > >
> > >
> >
> >
> > --
> > Daan
> >
>

Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Wei ZHOU <us...@gmail.com>.
Agree with Daan.  go for it @Daniel

One problem that needs to be solved is, there are few SQL upgrade scripts
that rely on views. You can check by command

git grep "_view" engine/schema/src/main/ |egrep -v -i 'DROP VIEW|CREATE
VIEW'

Kind regards,
Wei







On Tue, 14 Feb 2023 at 14:27, Daan Hoogland <da...@gmail.com> wrote:

> Daniel, I think this is a lazy consensus issue and any further discussion
> can happen on a PR. No vote thread needed.
>
> On Mon, Feb 13, 2023 at 10:45 PM Daniel Salvador <gu...@apache.org>
> wrote:
>
> > I think I messed up with the format of my last email. Here follows the
> > message in the correct format:
> >
> > ---
> >
> > Thank you for the replies, guys.
> >
> > I agree using frameworks (ORM and/or OOQ) might facilitate CloudStack's
> > developers' life. Given the complexity of the project and the whole
> > analysis and discussion necessary, it would require a lot of effort and
> > time to implement it, as Daan mentioned; we could open a new discussion
> on
> > this topic later.
> >
> > Regarding the enforcement, we could validate it via GitHub actions, as
> > Rohit suggested; and add the instructions in our Coding Convention on
> > Confluence[¹] as well.
> >
> > About Wei's suggestion on having all views in a single file, in my
> opinion,
> > having a separate file for each "VIEW" rather than all in a single file
> > would be more organized and facilitate the diff checking and change
> > tracking, but we can better discuss the pros and cons of each approach.
> >
> > ---
> >
> > Summarizing what we discussed so far, to improve the database's "VIEW"s
> > management, we can have two phases: in the first phase, we manage the
> > "VIEW"s via specific files (or all "VIEW"s in a single file), executing
> > them after each version upgrade; in a second phase, we could add a
> > framework to ACS to improve the whole database management.
> >
> > Should I open a vote thread for the proposal of the first phase or can I
> > already open a PR with the POC and we discuss the details there?
> >
> > ---
> >
> > Best regards,
> > Daniel Salvador (gutoveronezi)
> >
> > [¹]:
> >
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Coding+conventions
> >
> > On Mon, Feb 13, 2023 at 6:37 PM Daniel Salvador <gutoveronezi@apache.org
> >
> > wrote:
> >
> > > Thank you for the replies, guys.
> > >>
> > >> I agree using frameworks (ORM and/or OOQ) might facilitate
> CloudStack's
> > >> developers' life. Given the complexity of the project and the whole
> > >> analysis and discussion necessary, it would require a lot of effort
> and
> > >> time to implement it, as Daan mentioned; we could open a new
> discussion
> > on
> > >> this topic later.
> > >>
> > >> Regarding the enforcement, we could validate it via GitHub actions, as
> > >> Rohit suggested; and add the instructions in our Coding Convention on
> > >> Confluence[¹] as well.
> > >>
> > >> About Wei's suggestion on having all views in a single file, in my
> > >> opinion, having a separate file for each "VIEW" rather than all in a
> > single
> > >> file would be more organized and facilitate the diff checking and
> change
> > >> tracking, but we can discuss better the pros and cons of each
> approach.
> > >>
> > >> ---
> > >>
> > >> Summarizing what we discussed so far, to improve the database's
> "VIEW"s
> > >> management, we can have two phases: in the first phase, we manage the
> > >> "VIEW"s via specific files (or all "VIEW"s in a single file),
> executing
> > >> them after each version upgrade; in a second phase, we could add a
> > >> framework to ACS to improve the whole database management.
> > >>
> > >> Should I open a vote thread for the proposal of the first phase or
> can I
> > >> already open a PR with the POC and we discuss the details there?
> > >>
> > >> ---
> > >>
> > >> Best regards,
> > >> Daniel Salvador (gutoveronezi)
> > >>
> > >> [¹]:
> > >>
> >
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Coding+conventions
> > >>
> > >
> >
>
>
> --
> Daan
>

Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Daan Hoogland <da...@gmail.com>.
Daniel, I think this is a lazy consensus issue and any further discussion
can happen on a PR. No vote thread needed.

On Mon, Feb 13, 2023 at 10:45 PM Daniel Salvador <gu...@apache.org>
wrote:

> I think I messed up with the format of my last email. Here follows the
> message in the correct format:
>
> ---
>
> Thank you for the replies, guys.
>
> I agree using frameworks (ORM and/or OOQ) might facilitate CloudStack's
> developers' life. Given the complexity of the project and the whole
> analysis and discussion necessary, it would require a lot of effort and
> time to implement it, as Daan mentioned; we could open a new discussion on
> this topic later.
>
> Regarding the enforcement, we could validate it via GitHub actions, as
> Rohit suggested; and add the instructions in our Coding Convention on
> Confluence[¹] as well.
>
> About Wei's suggestion on having all views in a single file, in my opinion,
> having a separate file for each "VIEW" rather than all in a single file
> would be more organized and facilitate the diff checking and change
> tracking, but we can better discuss the pros and cons of each approach.
>
> ---
>
> Summarizing what we discussed so far, to improve the database's "VIEW"s
> management, we can have two phases: in the first phase, we manage the
> "VIEW"s via specific files (or all "VIEW"s in a single file), executing
> them after each version upgrade; in a second phase, we could add a
> framework to ACS to improve the whole database management.
>
> Should I open a vote thread for the proposal of the first phase or can I
> already open a PR with the POC and we discuss the details there?
>
> ---
>
> Best regards,
> Daniel Salvador (gutoveronezi)
>
> [¹]:
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Coding+conventions
>
> On Mon, Feb 13, 2023 at 6:37 PM Daniel Salvador <gu...@apache.org>
> wrote:
>
> > Thank you for the replies, guys.
> >>
> >> I agree using frameworks (ORM and/or OOQ) might facilitate CloudStack's
> >> developers' life. Given the complexity of the project and the whole
> >> analysis and discussion necessary, it would require a lot of effort and
> >> time to implement it, as Daan mentioned; we could open a new discussion
> on
> >> this topic later.
> >>
> >> Regarding the enforcement, we could validate it via GitHub actions, as
> >> Rohit suggested; and add the instructions in our Coding Convention on
> >> Confluence[¹] as well.
> >>
> >> About Wei's suggestion on having all views in a single file, in my
> >> opinion, having a separate file for each "VIEW" rather than all in a
> single
> >> file would be more organized and facilitate the diff checking and change
> >> tracking, but we can discuss better the pros and cons of each approach.
> >>
> >> ---
> >>
> >> Summarizing what we discussed so far, to improve the database's "VIEW"s
> >> management, we can have two phases: in the first phase, we manage the
> >> "VIEW"s via specific files (or all "VIEW"s in a single file), executing
> >> them after each version upgrade; in a second phase, we could add a
> >> framework to ACS to improve the whole database management.
> >>
> >> Should I open a vote thread for the proposal of the first phase or can I
> >> already open a PR with the POC and we discuss the details there?
> >>
> >> ---
> >>
> >> Best regards,
> >> Daniel Salvador (gutoveronezi)
> >>
> >> [¹]:
> >>
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Coding+conventions
> >>
> >
>


-- 
Daan

Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Daniel Salvador <gu...@apache.org>.
I think I messed up with the format of my last email. Here follows the
message in the correct format:

---

Thank you for the replies, guys.

I agree using frameworks (ORM and/or OOQ) might facilitate CloudStack's
developers' life. Given the complexity of the project and the whole
analysis and discussion necessary, it would require a lot of effort and
time to implement it, as Daan mentioned; we could open a new discussion on
this topic later.

Regarding the enforcement, we could validate it via GitHub actions, as
Rohit suggested; and add the instructions in our Coding Convention on
Confluence[¹] as well.

About Wei's suggestion on having all views in a single file, in my opinion,
having a separate file for each "VIEW" rather than all in a single file
would be more organized and facilitate the diff checking and change
tracking, but we can better discuss the pros and cons of each approach.

---

Summarizing what we discussed so far, to improve the database's "VIEW"s
management, we can have two phases: in the first phase, we manage the
"VIEW"s via specific files (or all "VIEW"s in a single file), executing
them after each version upgrade; in a second phase, we could add a
framework to ACS to improve the whole database management.

Should I open a vote thread for the proposal of the first phase or can I
already open a PR with the POC and we discuss the details there?

---

Best regards,
Daniel Salvador (gutoveronezi)

[¹]:
https://cwiki.apache.org/confluence/display/CLOUDSTACK/Coding+conventions

On Mon, Feb 13, 2023 at 6:37 PM Daniel Salvador <gu...@apache.org>
wrote:

> Thank you for the replies, guys.
>>
>> I agree using frameworks (ORM and/or OOQ) might facilitate CloudStack's
>> developers' life. Given the complexity of the project and the whole
>> analysis and discussion necessary, it would require a lot of effort and
>> time to implement it, as Daan mentioned; we could open a new discussion on
>> this topic later.
>>
>> Regarding the enforcement, we could validate it via GitHub actions, as
>> Rohit suggested; and add the instructions in our Coding Convention on
>> Confluence[¹] as well.
>>
>> About Wei's suggestion on having all views in a single file, in my
>> opinion, having a separate file for each "VIEW" rather than all in a single
>> file would be more organized and facilitate the diff checking and change
>> tracking, but we can discuss better the pros and cons of each approach.
>>
>> ---
>>
>> Summarizing what we discussed so far, to improve the database's "VIEW"s
>> management, we can have two phases: in the first phase, we manage the
>> "VIEW"s via specific files (or all "VIEW"s in a single file), executing
>> them after each version upgrade; in a second phase, we could add a
>> framework to ACS to improve the whole database management.
>>
>> Should I open a vote thread for the proposal of the first phase or can I
>> already open a PR with the POC and we discuss the details there?
>>
>> ---
>>
>> Best regards,
>> Daniel Salvador (gutoveronezi)
>>
>> [¹]:
>> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Coding+conventions
>>
>

Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Daniel Salvador <gu...@apache.org>.
>
> Thank you for the replies, guys.
>
> I agree using frameworks (ORM and/or OOQ) might facilitate CloudStack's
> developers' life. Given the complexity of the project and the whole
> analysis and discussion necessary, it would require a lot of effort and
> time to implement it, as Daan mentioned; we could open a new discussion on
> this topic later.
>
> Regarding the enforcement, we could validate it via GitHub actions, as
> Rohit suggested; and add the instructions in our Coding Convention on
> Confluence[¹] as well.
>
> About Wei's suggestion on having all views in a single file, in my
> opinion, having a separate file for each "VIEW" rather than all in a single
> file would be more organized and facilitate the diff checking and change
> tracking, but we can discuss better the pros and cons of each approach.
>
> ---
>
> Summarizing what we discussed so far, to improve the database's "VIEW"s
> management, we can have two phases: in the first phase, we manage the
> "VIEW"s via specific files (or all "VIEW"s in a single file), executing
> them after each version upgrade; in a second phase, we could add a
> framework to ACS to improve the whole database management.
>
> Should I open a vote thread for the proposal of the first phase or can I
> already open a PR with the POC and we discuss the details there?
>
> ---
>
> Best regards,
> Daniel Salvador (gutoveronezi)
>
> [¹]:
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/Coding+conventions
>

Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Daan Hoogland <da...@gmail.com>.
I like your ideas as well @Rohit Yadav <ro...@shapeblue.com> and @Wei
ZHOU <us...@gmail.com> , but that is a step further than what Daniel
is proposing and his idea is a good step forward.
As for the schema-create-views.sql, that would be possible and maybe even
neater to split in a schema-drop-views.sql to be run before upgrades and
the create script for afterwards.

Any more beautiful implementation like jooq or flyway is good but will
require a lot of zeal and resources. For one thing we must deal with the
GenericDao<> in a backwards compatible way. There are other technical debt
issues that would take precedence when it comes down to me. (e.g. gson
upgrade and a lot of other older dependencies).

this ^ is no minus one on any idea, just caution.


On Wed, Feb 8, 2023 at 9:02 AM Wei ZHOU <us...@gmail.com> wrote:

> I totally agree with Rohit.
>
> Anyway, it is a very nice idea. It will be very helpful when we make SQL
> changes on VIEWs on both a fork and main branch.
>
> Can we have all views in a separated file, for
> example schema-create-views.sql, and run the SQL as the last step when all
> other SQL changes are done in upgrade ?
> This could reduce the complexity of coding , porting/backporting etc.
>
>
> -Wei
>
>
>
>
>
>
>
> On Wed, 8 Feb 2023 at 08:01, Rohit Yadav <ro...@shapeblue.com>
> wrote:
>
> > That's a good idea but would create two ways of applying SQL changes
> > during upgrade. Nicolas's point where removal is needed may be handled by
> > just a drop statement in the views sql file.
> >
> > The other issue I see is lack of some kind of enforcement, validation, or
> > check (it may be possible to do those via a Github Actions validation
> > check, or simply changing how we declare the views/schema
> programmatically
> > using something like jooq [1] that gives type-checking and API and can
> work
> > with GenericDaoBase).
> >
> > The bigger and general issue of error-prone SQL upgrade paths remains
> > unanswered. We may need to explore migrating to something like flyway [2]
> > or similar. For example, when working with something like Django or
> > Ruby-on-Rails, DB migration is something very fun and automatic - that
> sort
> > of automation and developer experience in CloudStack would be great.
> >
> > [1]
> >
> https://www.jooq.org/doc/latest/manual/sql-building/ddl-statements/create-statement/create-view-statement/
> > [2] https://flywaydb.org/
> >
> >
> > Regards.
> >
> > ________________________________
> > From: Daan Hoogland <da...@gmail.com>
> > Sent: Tuesday, February 7, 2023 19:12
> > To: dev@cloudstack.apache.org <de...@cloudstack.apache.org>
> > Subject: Re: [DISCUSSION] Management of the database's "VIEW"s
> >
> > nice guys, i think we should go with it. Less error prone than our
> current
> > MO
> >
> > On Tue, Feb 7, 2023 at 2:13 PM Daniel Salvador <gu...@apache.org>
> > wrote:
> >
> > > Nicolas,
> > >
> > > I had not thought about this case. I think your suggestion is nice; we
> > can
> > > use this approach.
> > >
> > > Best regards,
> > > Daniel Salvador (gutoveronezi)
> > >
> > > On Tue, Feb 7, 2023 at 9:45 AM Nicolas Vazquez <
> > > Nicolas.Vazquez@shapeblue.com> wrote:
> > >
> > > > Thanks Daniel, that approach looks nice to me.
> > > >
> > > > How would it work in case a view needs to be removed? I would think
> we
> > > can
> > > > remove the file from the views directory and add the drop view SQL on
> > the
> > > > schema file.
> > > >
> > > > Regards,
> > > > Nicolas Vazquez
> > > > ________________________________
> > > > From: Daniel Augusto Veronezi Salvador <dv...@gmail.com>
> > > > Sent: Monday, February 6, 2023 9:43 PM
> > > > To: dev@cloudstack.apache.org <de...@cloudstack.apache.org>
> > > > Subject: [DISCUSSION] Management of the database's "VIEW"s
> > > >
> > > > Hello guys,
> > > >
> > > > I would like to open a discussion on our current management of the
> > > > database's "VIEW"s.
> > > >
> > > > Currently, we have to look at the changes in the previous "schema"
> > files
> > > > and replicate the whole "CREATE VIEW" command in the current "schema"
> > > file,
> > > > modifying what we need (adding/removing columns, and so on). This
> > process
> > > > makes the changes in a "VIEW" to be distributed through several
> files,
> > > > increasing the number of lines modified for simple changes (e.g.: for
> > > > adding a single field to the "VIEW" result we need to replicate the
> > whole
> > > > command); thus, making it difficult to maintain and track.
> > > >
> > > > With that in mind, I had some ideas of how we can improve this
> process.
> > > > The proposal is: instead of adding the changes to the current
> "schema"
> > > > file, we create unique files for each "VIEW" and manage them; more
> > > detailed:
> > > > 1. under the directory "db", where the "schema" files are, we would
> > > create
> > > > a sub-directory called "views";
> > > > 2. in the sub-directory "views", we would create a file for each
> > "VIEW",
> > > > named with the "VIEW" name (for instance,
> > > > "cloud.network_offering_view.sql");
> > > > 3. in the "VIEW" file, we would put the "DROP VIEW" command, followed
> > by
> > > > the "CREATE VIEW" command, just as we do in the "schema" file; for
> > > > instance, the content of file "cloud.network_offering_view.sql" would
> > be:
> > > >
> > > > ```
> > > > DROP VIEW IF EXISTS `cloud`.`network_offering_view`;
> > > >
> > > > CREATE VIEW `cloud`.`network_offering_view` AS
> > > >      SELECT
> > > >          `network_offerings`.`id` AS `id`,
> > > >          `network_offerings`.`uuid` AS `uuid`,
> > > >          `network_offerings`.`name` AS `name`,
> > > >      <the rest of the CREATE VIEW command>
> > > > ```
> > > >
> > > > 4. then, after each version upgrade, in Java we execute all the files
> > in
> > > > the sub-directory "views"; this way, if a "VIEW" changed, it would be
> > > > recreated with the new changes; otherwise, it would be only recreated
> > as
> > > is;
> > > >
> > > > That would allow us to easily track "VIEW" modifications, as we would
> > > just
> > > > change the "VIEW" declaration in the same file, instead of
> re-declaring
> > > the
> > > > whole "VIEW" in a different file; and we would have a better history
> of
> > > the
> > > > changes. Also, we would not need to migrate all "VIEW"s right away;
> we
> > > > could migrate as we change them.
> > > >
> > > > Please, let me know your thoughts about the proposal.
> > > >
> > > > Best regards,
> > > > Daniel Salvador (gutoveronezi)
> > > >
> > > >
> > > >
> > > >
> > >
> >
> >
> > --
> > Daan
> >
> >
> >
> >
>


-- 
Daan

Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Wei ZHOU <us...@gmail.com>.
I totally agree with Rohit.

Anyway, it is a very nice idea. It will be very helpful when we make SQL
changes on VIEWs on both a fork and main branch.

Can we have all views in a separated file, for
example schema-create-views.sql, and run the SQL as the last step when all
other SQL changes are done in upgrade ?
This could reduce the complexity of coding , porting/backporting etc.


-Wei







On Wed, 8 Feb 2023 at 08:01, Rohit Yadav <ro...@shapeblue.com> wrote:

> That's a good idea but would create two ways of applying SQL changes
> during upgrade. Nicolas's point where removal is needed may be handled by
> just a drop statement in the views sql file.
>
> The other issue I see is lack of some kind of enforcement, validation, or
> check (it may be possible to do those via a Github Actions validation
> check, or simply changing how we declare the views/schema programmatically
> using something like jooq [1] that gives type-checking and API and can work
> with GenericDaoBase).
>
> The bigger and general issue of error-prone SQL upgrade paths remains
> unanswered. We may need to explore migrating to something like flyway [2]
> or similar. For example, when working with something like Django or
> Ruby-on-Rails, DB migration is something very fun and automatic - that sort
> of automation and developer experience in CloudStack would be great.
>
> [1]
> https://www.jooq.org/doc/latest/manual/sql-building/ddl-statements/create-statement/create-view-statement/
> [2] https://flywaydb.org/
>
>
> Regards.
>
> ________________________________
> From: Daan Hoogland <da...@gmail.com>
> Sent: Tuesday, February 7, 2023 19:12
> To: dev@cloudstack.apache.org <de...@cloudstack.apache.org>
> Subject: Re: [DISCUSSION] Management of the database's "VIEW"s
>
> nice guys, i think we should go with it. Less error prone than our current
> MO
>
> On Tue, Feb 7, 2023 at 2:13 PM Daniel Salvador <gu...@apache.org>
> wrote:
>
> > Nicolas,
> >
> > I had not thought about this case. I think your suggestion is nice; we
> can
> > use this approach.
> >
> > Best regards,
> > Daniel Salvador (gutoveronezi)
> >
> > On Tue, Feb 7, 2023 at 9:45 AM Nicolas Vazquez <
> > Nicolas.Vazquez@shapeblue.com> wrote:
> >
> > > Thanks Daniel, that approach looks nice to me.
> > >
> > > How would it work in case a view needs to be removed? I would think we
> > can
> > > remove the file from the views directory and add the drop view SQL on
> the
> > > schema file.
> > >
> > > Regards,
> > > Nicolas Vazquez
> > > ________________________________
> > > From: Daniel Augusto Veronezi Salvador <dv...@gmail.com>
> > > Sent: Monday, February 6, 2023 9:43 PM
> > > To: dev@cloudstack.apache.org <de...@cloudstack.apache.org>
> > > Subject: [DISCUSSION] Management of the database's "VIEW"s
> > >
> > > Hello guys,
> > >
> > > I would like to open a discussion on our current management of the
> > > database's "VIEW"s.
> > >
> > > Currently, we have to look at the changes in the previous "schema"
> files
> > > and replicate the whole "CREATE VIEW" command in the current "schema"
> > file,
> > > modifying what we need (adding/removing columns, and so on). This
> process
> > > makes the changes in a "VIEW" to be distributed through several files,
> > > increasing the number of lines modified for simple changes (e.g.: for
> > > adding a single field to the "VIEW" result we need to replicate the
> whole
> > > command); thus, making it difficult to maintain and track.
> > >
> > > With that in mind, I had some ideas of how we can improve this process.
> > > The proposal is: instead of adding the changes to the current "schema"
> > > file, we create unique files for each "VIEW" and manage them; more
> > detailed:
> > > 1. under the directory "db", where the "schema" files are, we would
> > create
> > > a sub-directory called "views";
> > > 2. in the sub-directory "views", we would create a file for each
> "VIEW",
> > > named with the "VIEW" name (for instance,
> > > "cloud.network_offering_view.sql");
> > > 3. in the "VIEW" file, we would put the "DROP VIEW" command, followed
> by
> > > the "CREATE VIEW" command, just as we do in the "schema" file; for
> > > instance, the content of file "cloud.network_offering_view.sql" would
> be:
> > >
> > > ```
> > > DROP VIEW IF EXISTS `cloud`.`network_offering_view`;
> > >
> > > CREATE VIEW `cloud`.`network_offering_view` AS
> > >      SELECT
> > >          `network_offerings`.`id` AS `id`,
> > >          `network_offerings`.`uuid` AS `uuid`,
> > >          `network_offerings`.`name` AS `name`,
> > >      <the rest of the CREATE VIEW command>
> > > ```
> > >
> > > 4. then, after each version upgrade, in Java we execute all the files
> in
> > > the sub-directory "views"; this way, if a "VIEW" changed, it would be
> > > recreated with the new changes; otherwise, it would be only recreated
> as
> > is;
> > >
> > > That would allow us to easily track "VIEW" modifications, as we would
> > just
> > > change the "VIEW" declaration in the same file, instead of re-declaring
> > the
> > > whole "VIEW" in a different file; and we would have a better history of
> > the
> > > changes. Also, we would not need to migrate all "VIEW"s right away; we
> > > could migrate as we change them.
> > >
> > > Please, let me know your thoughts about the proposal.
> > >
> > > Best regards,
> > > Daniel Salvador (gutoveronezi)
> > >
> > >
> > >
> > >
> >
>
>
> --
> Daan
>
>
>
>

Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Rohit Yadav <ro...@shapeblue.com>.
That's a good idea but would create two ways of applying SQL changes during upgrade. Nicolas's point where removal is needed may be handled by just a drop statement in the views sql file.

The other issue I see is lack of some kind of enforcement, validation, or check (it may be possible to do those via a Github Actions validation check, or simply changing how we declare the views/schema programmatically using something like jooq [1] that gives type-checking and API and can work with GenericDaoBase).

The bigger and general issue of error-prone SQL upgrade paths remains unanswered. We may need to explore migrating to something like flyway [2] or similar. For example, when working with something like Django or Ruby-on-Rails, DB migration is something very fun and automatic - that sort of automation and developer experience in CloudStack would be great.

[1] https://www.jooq.org/doc/latest/manual/sql-building/ddl-statements/create-statement/create-view-statement/
[2] https://flywaydb.org/


Regards.

________________________________
From: Daan Hoogland <da...@gmail.com>
Sent: Tuesday, February 7, 2023 19:12
To: dev@cloudstack.apache.org <de...@cloudstack.apache.org>
Subject: Re: [DISCUSSION] Management of the database's "VIEW"s

nice guys, i think we should go with it. Less error prone than our current
MO

On Tue, Feb 7, 2023 at 2:13 PM Daniel Salvador <gu...@apache.org>
wrote:

> Nicolas,
>
> I had not thought about this case. I think your suggestion is nice; we can
> use this approach.
>
> Best regards,
> Daniel Salvador (gutoveronezi)
>
> On Tue, Feb 7, 2023 at 9:45 AM Nicolas Vazquez <
> Nicolas.Vazquez@shapeblue.com> wrote:
>
> > Thanks Daniel, that approach looks nice to me.
> >
> > How would it work in case a view needs to be removed? I would think we
> can
> > remove the file from the views directory and add the drop view SQL on the
> > schema file.
> >
> > Regards,
> > Nicolas Vazquez
> > ________________________________
> > From: Daniel Augusto Veronezi Salvador <dv...@gmail.com>
> > Sent: Monday, February 6, 2023 9:43 PM
> > To: dev@cloudstack.apache.org <de...@cloudstack.apache.org>
> > Subject: [DISCUSSION] Management of the database's "VIEW"s
> >
> > Hello guys,
> >
> > I would like to open a discussion on our current management of the
> > database's "VIEW"s.
> >
> > Currently, we have to look at the changes in the previous "schema" files
> > and replicate the whole "CREATE VIEW" command in the current "schema"
> file,
> > modifying what we need (adding/removing columns, and so on). This process
> > makes the changes in a "VIEW" to be distributed through several files,
> > increasing the number of lines modified for simple changes (e.g.: for
> > adding a single field to the "VIEW" result we need to replicate the whole
> > command); thus, making it difficult to maintain and track.
> >
> > With that in mind, I had some ideas of how we can improve this process.
> > The proposal is: instead of adding the changes to the current "schema"
> > file, we create unique files for each "VIEW" and manage them; more
> detailed:
> > 1. under the directory "db", where the "schema" files are, we would
> create
> > a sub-directory called "views";
> > 2. in the sub-directory "views", we would create a file for each "VIEW",
> > named with the "VIEW" name (for instance,
> > "cloud.network_offering_view.sql");
> > 3. in the "VIEW" file, we would put the "DROP VIEW" command, followed by
> > the "CREATE VIEW" command, just as we do in the "schema" file; for
> > instance, the content of file "cloud.network_offering_view.sql" would be:
> >
> > ```
> > DROP VIEW IF EXISTS `cloud`.`network_offering_view`;
> >
> > CREATE VIEW `cloud`.`network_offering_view` AS
> >      SELECT
> >          `network_offerings`.`id` AS `id`,
> >          `network_offerings`.`uuid` AS `uuid`,
> >          `network_offerings`.`name` AS `name`,
> >      <the rest of the CREATE VIEW command>
> > ```
> >
> > 4. then, after each version upgrade, in Java we execute all the files in
> > the sub-directory "views"; this way, if a "VIEW" changed, it would be
> > recreated with the new changes; otherwise, it would be only recreated as
> is;
> >
> > That would allow us to easily track "VIEW" modifications, as we would
> just
> > change the "VIEW" declaration in the same file, instead of re-declaring
> the
> > whole "VIEW" in a different file; and we would have a better history of
> the
> > changes. Also, we would not need to migrate all "VIEW"s right away; we
> > could migrate as we change them.
> >
> > Please, let me know your thoughts about the proposal.
> >
> > Best regards,
> > Daniel Salvador (gutoveronezi)
> >
> >
> >
> >
>


--
Daan

 


Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Daan Hoogland <da...@gmail.com>.
nice guys, i think we should go with it. Less error prone than our current
MO

On Tue, Feb 7, 2023 at 2:13 PM Daniel Salvador <gu...@apache.org>
wrote:

> Nicolas,
>
> I had not thought about this case. I think your suggestion is nice; we can
> use this approach.
>
> Best regards,
> Daniel Salvador (gutoveronezi)
>
> On Tue, Feb 7, 2023 at 9:45 AM Nicolas Vazquez <
> Nicolas.Vazquez@shapeblue.com> wrote:
>
> > Thanks Daniel, that approach looks nice to me.
> >
> > How would it work in case a view needs to be removed? I would think we
> can
> > remove the file from the views directory and add the drop view SQL on the
> > schema file.
> >
> > Regards,
> > Nicolas Vazquez
> > ________________________________
> > From: Daniel Augusto Veronezi Salvador <dv...@gmail.com>
> > Sent: Monday, February 6, 2023 9:43 PM
> > To: dev@cloudstack.apache.org <de...@cloudstack.apache.org>
> > Subject: [DISCUSSION] Management of the database's "VIEW"s
> >
> > Hello guys,
> >
> > I would like to open a discussion on our current management of the
> > database's "VIEW"s.
> >
> > Currently, we have to look at the changes in the previous "schema" files
> > and replicate the whole "CREATE VIEW" command in the current "schema"
> file,
> > modifying what we need (adding/removing columns, and so on). This process
> > makes the changes in a "VIEW" to be distributed through several files,
> > increasing the number of lines modified for simple changes (e.g.: for
> > adding a single field to the "VIEW" result we need to replicate the whole
> > command); thus, making it difficult to maintain and track.
> >
> > With that in mind, I had some ideas of how we can improve this process.
> > The proposal is: instead of adding the changes to the current "schema"
> > file, we create unique files for each "VIEW" and manage them; more
> detailed:
> > 1. under the directory "db", where the "schema" files are, we would
> create
> > a sub-directory called "views";
> > 2. in the sub-directory "views", we would create a file for each "VIEW",
> > named with the "VIEW" name (for instance,
> > "cloud.network_offering_view.sql");
> > 3. in the "VIEW" file, we would put the "DROP VIEW" command, followed by
> > the "CREATE VIEW" command, just as we do in the "schema" file; for
> > instance, the content of file "cloud.network_offering_view.sql" would be:
> >
> > ```
> > DROP VIEW IF EXISTS `cloud`.`network_offering_view`;
> >
> > CREATE VIEW `cloud`.`network_offering_view` AS
> >      SELECT
> >          `network_offerings`.`id` AS `id`,
> >          `network_offerings`.`uuid` AS `uuid`,
> >          `network_offerings`.`name` AS `name`,
> >      <the rest of the CREATE VIEW command>
> > ```
> >
> > 4. then, after each version upgrade, in Java we execute all the files in
> > the sub-directory "views"; this way, if a "VIEW" changed, it would be
> > recreated with the new changes; otherwise, it would be only recreated as
> is;
> >
> > That would allow us to easily track "VIEW" modifications, as we would
> just
> > change the "VIEW" declaration in the same file, instead of re-declaring
> the
> > whole "VIEW" in a different file; and we would have a better history of
> the
> > changes. Also, we would not need to migrate all "VIEW"s right away; we
> > could migrate as we change them.
> >
> > Please, let me know your thoughts about the proposal.
> >
> > Best regards,
> > Daniel Salvador (gutoveronezi)
> >
> >
> >
> >
>


-- 
Daan

Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Daniel Salvador <gu...@apache.org>.
Nicolas,

I had not thought about this case. I think your suggestion is nice; we can
use this approach.

Best regards,
Daniel Salvador (gutoveronezi)

On Tue, Feb 7, 2023 at 9:45 AM Nicolas Vazquez <
Nicolas.Vazquez@shapeblue.com> wrote:

> Thanks Daniel, that approach looks nice to me.
>
> How would it work in case a view needs to be removed? I would think we can
> remove the file from the views directory and add the drop view SQL on the
> schema file.
>
> Regards,
> Nicolas Vazquez
> ________________________________
> From: Daniel Augusto Veronezi Salvador <dv...@gmail.com>
> Sent: Monday, February 6, 2023 9:43 PM
> To: dev@cloudstack.apache.org <de...@cloudstack.apache.org>
> Subject: [DISCUSSION] Management of the database's "VIEW"s
>
> Hello guys,
>
> I would like to open a discussion on our current management of the
> database's "VIEW"s.
>
> Currently, we have to look at the changes in the previous "schema" files
> and replicate the whole "CREATE VIEW" command in the current "schema" file,
> modifying what we need (adding/removing columns, and so on). This process
> makes the changes in a "VIEW" to be distributed through several files,
> increasing the number of lines modified for simple changes (e.g.: for
> adding a single field to the "VIEW" result we need to replicate the whole
> command); thus, making it difficult to maintain and track.
>
> With that in mind, I had some ideas of how we can improve this process.
> The proposal is: instead of adding the changes to the current "schema"
> file, we create unique files for each "VIEW" and manage them; more detailed:
> 1. under the directory "db", where the "schema" files are, we would create
> a sub-directory called "views";
> 2. in the sub-directory "views", we would create a file for each "VIEW",
> named with the "VIEW" name (for instance,
> "cloud.network_offering_view.sql");
> 3. in the "VIEW" file, we would put the "DROP VIEW" command, followed by
> the "CREATE VIEW" command, just as we do in the "schema" file; for
> instance, the content of file "cloud.network_offering_view.sql" would be:
>
> ```
> DROP VIEW IF EXISTS `cloud`.`network_offering_view`;
>
> CREATE VIEW `cloud`.`network_offering_view` AS
>      SELECT
>          `network_offerings`.`id` AS `id`,
>          `network_offerings`.`uuid` AS `uuid`,
>          `network_offerings`.`name` AS `name`,
>      <the rest of the CREATE VIEW command>
> ```
>
> 4. then, after each version upgrade, in Java we execute all the files in
> the sub-directory "views"; this way, if a "VIEW" changed, it would be
> recreated with the new changes; otherwise, it would be only recreated as is;
>
> That would allow us to easily track "VIEW" modifications, as we would just
> change the "VIEW" declaration in the same file, instead of re-declaring the
> whole "VIEW" in a different file; and we would have a better history of the
> changes. Also, we would not need to migrate all "VIEW"s right away; we
> could migrate as we change them.
>
> Please, let me know your thoughts about the proposal.
>
> Best regards,
> Daniel Salvador (gutoveronezi)
>
>
>
>

Re: [DISCUSSION] Management of the database's "VIEW"s

Posted by Nicolas Vazquez <Ni...@shapeblue.com>.
Thanks Daniel, that approach looks nice to me.

How would it work in case a view needs to be removed? I would think we can remove the file from the views directory and add the drop view SQL on the schema file.

Regards,
Nicolas Vazquez
________________________________
From: Daniel Augusto Veronezi Salvador <dv...@gmail.com>
Sent: Monday, February 6, 2023 9:43 PM
To: dev@cloudstack.apache.org <de...@cloudstack.apache.org>
Subject: [DISCUSSION] Management of the database's "VIEW"s

Hello guys,

I would like to open a discussion on our current management of the database's "VIEW"s.

Currently, we have to look at the changes in the previous "schema" files and replicate the whole "CREATE VIEW" command in the current "schema" file, modifying what we need (adding/removing columns, and so on). This process makes the changes in a "VIEW" to be distributed through several files, increasing the number of lines modified for simple changes (e.g.: for adding a single field to the "VIEW" result we need to replicate the whole command); thus, making it difficult to maintain and track.

With that in mind, I had some ideas of how we can improve this process. The proposal is: instead of adding the changes to the current "schema" file, we create unique files for each "VIEW" and manage them; more detailed:
1. under the directory "db", where the "schema" files are, we would create a sub-directory called "views";
2. in the sub-directory "views", we would create a file for each "VIEW", named with the "VIEW" name (for instance, "cloud.network_offering_view.sql");
3. in the "VIEW" file, we would put the "DROP VIEW" command, followed by the "CREATE VIEW" command, just as we do in the "schema" file; for instance, the content of file "cloud.network_offering_view.sql" would be:

```
DROP VIEW IF EXISTS `cloud`.`network_offering_view`;

CREATE VIEW `cloud`.`network_offering_view` AS
     SELECT
         `network_offerings`.`id` AS `id`,
         `network_offerings`.`uuid` AS `uuid`,
         `network_offerings`.`name` AS `name`,
     <the rest of the CREATE VIEW command>
```

4. then, after each version upgrade, in Java we execute all the files in the sub-directory "views"; this way, if a "VIEW" changed, it would be recreated with the new changes; otherwise, it would be only recreated as is;

That would allow us to easily track "VIEW" modifications, as we would just change the "VIEW" declaration in the same file, instead of re-declaring the whole "VIEW" in a different file; and we would have a better history of the changes. Also, we would not need to migrate all "VIEW"s right away; we could migrate as we change them.

Please, let me know your thoughts about the proposal.

Best regards,
Daniel Salvador (gutoveronezi)