Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Support Table/Field creation from Table structure #1

Open
ocomsoft opened this issue Oct 4, 2020 · 5 comments
Open

Suggestion: Support Table/Field creation from Table structure #1

ocomsoft opened this issue Oct 4, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@ocomsoft
Copy link

ocomsoft commented Oct 4, 2020

When going to production you need to ensure the database is the same structure. It would make sense that we can run a function to create any missing tables/fields based on the structure generated

Just a suggestion.

@bokwoon95
Copy link
Owner

Something like an automatic migration that reads the table struct definitions in a Go file and runs CREATE TABLE/ALTER TABLE ADD COLUMNS accordingly?

@ocomsoft
Copy link
Author

ocomsoft commented Oct 4, 2020

Yeah. So if there is a Table or Field not in the database it adds it. I would not delete columns or tables.

Bonus points would be to change types but that could be very complex :)

@bokwoon95
Copy link
Owner

I've thought about this feature before, but I'm not sure if it's the right decision to generate the DDL statements based on the Go structs. It's nice to have some migration syntactic sugar like this but if I were to implement it, I would want to consider everything (delete tables, columns, rename columns, change types, etc). For example, if I decide not to delete tables or columns (a good choice btw) I must consider what are the alternatives that the programmer can take? Does it fit well with my proposed solution? There is a whole set of questions I must ask first, and I'm not sure about the answers.

In the current workflow, the code-generated struct definitions shouldn't be edited manually but instead generated from the database. So if I wanted to reference a new column in my code I must add it into the database first, which guarantees that the column already exists. That addresses the concern right?

@ocomsoft
Copy link
Author

ocomsoft commented Oct 6, 2020

Ok so the bit I think you are missing is a typical workflow.

The developer adds a field to a table (or a NEW table) and then adds the code to program then rebuilds the problem.. but then they want to put this into a testing server then later a production server.. how we do we ensure the databases have the same table structure that the code expects?

I would suggest a method must be called to do the 'migration' so they can choose to use this or not. But to me, I would like the code to ensure you have the fields in whatever database I use based on what the code is written to expect.

If the user needs more complex features than that then that is another problem. ie a new set of methods to create tables, fields etc...

I mean you don't have to have this feature. I just thought it would make sense.. I think I would end up using a combination of Gorm (that does something similar to what I described) and this library.

Once again - great work - Hope this is a success for you.

@bokwoon95
Copy link
Owner

Thanks for clarifying the workflow. It's quite helpful to know what the various workflows out there in the wild are like. I'll give it some more thought and also on how to implement it.

@bokwoon95 bokwoon95 added the enhancement New feature or request label Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants