YAGNI and database creation scripts

Now I have the code that creates the database (just a few CREATE queries in the SQLite database) in my main database access class. This seems unnecessary as I am not going to use the code. I would just need it if something went wrong and I needed to recreate the database. Should I...

  • Leave things as they are, although the database creation code is about a quarter of my file size.
  • Move database creation code to a separate script. Most likely, I will launch it manually if I ever need to run it again, and this will put it out of sight while working on the main code.
  • Remove the database creation code and rely on version control if I ever need it again.
+3
source share
2 answers

I think it's better to save the code. More importantly, you must maintain this code (or generate it) every time you change the database schema.

This is important for the following reasons.

  • You will probably be surprised how many times you need it. If you need to move the server or configure another environment (for example, TEST or DEMO), etc.
  • I also found that I often refer to DDL SQL when coding, especially if I have not touched the system for a while.
  • You have a link to your decisions, such as the indexes you created, unique keys, etc. etc.

, , , , , . , (.. ) , .

+3

, - , .

. / , . , . , SQL , -, .

, ; 2 . script , .

+3

Source: https://habr.com/ru/post/1750672/


All Articles