Do you put your database static data into source-control ? How?

后端 未结 9 1621
逝去的感伤
逝去的感伤 2020-12-14 18:17

I\'m using SQL-Server 2008 with Visual Studio Database Edition.

With this setup, keeping your schema in sync is very easy. Basically, there\'s a \'compare schema\' t

相关标签:
9条回答
  • 2020-12-14 19:10

    The solution I use is to have create and change scripts in source control, coupled with version information stored in the database.

    Then, I have an install wizard that can detect whether it needs to create or update the db - the update process is managed by picking appropriate scripts based on the stored version information in the database.

    0 讨论(0)
  • 2020-12-14 19:12

    I really like your distinction of the three types of data.

    I agree for the third.

    In our application, we try to avoid putting in the database the first, because it is duplicated (as it has to be in the code, the database is a duplicate). A secondary benefice is that we need no join or query to get access to that value from the code, so this speed things up.

    If there is additional information that we would like to have in the database, for example if it can be changed per customer site, we separate the two. Other tables can still reference that data (either by index ex: 0, 1, 2, 3 or by code ex: EMPTY, SIMPLE, DOUBLE, ALL).

    For the second, the scripts should be in source-control. We separate them from the structure (I think they typically are replaced as time goes, while the structures keeps adding deltas).


    How do I (as a developer) warn the people doing the deployment that they should execute an insert statement ?

    We have a complete procedure for that, and a readme coming with each release, with scripts and so on...

    0 讨论(0)
  • 2020-12-14 19:14

    See this thread's answer. Static data from your first two points should be in source control, IMHO.

    Edit: *new

    • all-in-one or a separate script? it does not really matter as long as you (dev team) agree with your deployment team. I prefer to separate files, but I still can always create all-in-one.sql from those in the proper order [Logins, Roles, Users; Tables; Views; Stored Procedures; UDFs; Static Data; (Audit Tables, Audit Triggers)]
    • how do you make sure they execute it: well, make it another step in your application/database deployment documentation. If you roll out application which really needs specific (new) static data in the database, then you might want to perform a DB version check in your application. and you update the DB_VERSION to your new release number as part of that script. Then your application on a start-up should check it and report an error if the new DB version is required.
    • dev and non-dev static data: I have never seen this case actually. More often there is real static data, which you might call "dev", which is major configuration, ISO static data etc. The other type is default lookup data, which is there for users to start with, but they might add more. The mechanism to INSERT these data might be different, because you need to ensure you do not destoy (power-)user-created data.
    0 讨论(0)
提交回复
热议问题