开发者

Tool for Merging Multiple .SQL Files

开发者 https://www.devze.com 2023-03-26 12:53 出处:网络
Right now we have a ~5000 line .sql file consisting of tables, functions, triggers and other definition/declarations. The idea is to split开发者_StackOverflow社区 this into multiple sql files in order

Right now we have a ~5000 line .sql file consisting of tables, functions, triggers and other definition/declarations. The idea is to split开发者_StackOverflow社区 this into multiple sql files in order to restrain from having the same file being edited by multiple people at the same time. Then, right before build time the files will be merged back into one temporarily file where our scripts will then import and create the database.

My initial thoughts were to just create a bash script and concatenate the files in the appropriate order to rebuild the ~5000 line .sql file that can then be imported. I was curious if there was some type of mysql, psql or other linux specific command that was capable of doing this in a much more elegant and cleaner way?


It's hard to get cleaner than cat *.sql, IMHO. Just make sure you name the files so that a shell glob will expand to the correct inclusion order. i.e., if you have make-tables.sql and load-tables.sql then you can't use a simple * because that will put load- before make-.

Putting a number prefix in front of each file may remind you of old-school BASIC line numbers, but it works.

01-init.sql
10-create-tables.sql
15-create-indexes.sql
20-create-functions.sql
25-create-triggers.sql
75-load-data.sql
99-run-reports.sql

or something like that.

0

精彩评论

暂无评论...
验证码 换一张
取 消