2016-06-02 23:07:51 +02:00
|
|
|
var dbNameRand *rand.Rand
|
|
|
|
|
2016-07-15 07:32:36 +02:00
|
|
|
func MustTx(transactor boil.Transactor, err error) boil.Transactor {
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("Cannot create a transactor: %s", err))
|
|
|
|
}
|
|
|
|
return transactor
|
|
|
|
}
|
|
|
|
|
2016-09-14 06:46:58 +02:00
|
|
|
var rgxPGFkey = regexp.MustCompile(`(?m)^ALTER TABLE ONLY .*\n\s+ADD CONSTRAINT .*? FOREIGN KEY .*?;\n`)
|
2016-09-13 07:43:29 +02:00
|
|
|
var rgxMySQLkey = regexp.MustCompile(`(?m)((,\n)?\s+CONSTRAINT.*?FOREIGN KEY.*?\n)+`)
|
2017-03-13 14:24:08 +01:00
|
|
|
var rgxMSSQLkey = regexp.MustCompile(`(?m)^ALTER TABLE .*ADD\s+CONSTRAINT .* FOREIGN KEY.*?.*\n?REFERENCES.*`)
|
2016-06-02 23:07:51 +02:00
|
|
|
|
2016-09-14 06:46:58 +02:00
|
|
|
func newFKeyDestroyer(regex *regexp.Regexp, reader io.Reader) io.Reader {
|
2016-09-13 07:43:29 +02:00
|
|
|
return &fKeyDestroyer{
|
|
|
|
reader: reader,
|
2016-09-14 06:46:58 +02:00
|
|
|
rgx: regex,
|
2016-06-02 23:07:51 +02:00
|
|
|
}
|
2016-09-13 07:43:29 +02:00
|
|
|
}
|
2016-06-02 23:07:51 +02:00
|
|
|
|
2016-09-13 07:43:29 +02:00
|
|
|
type fKeyDestroyer struct {
|
|
|
|
reader io.Reader
|
|
|
|
buf *bytes.Buffer
|
2016-09-14 06:46:58 +02:00
|
|
|
rgx *regexp.Regexp
|
2016-06-02 23:07:51 +02:00
|
|
|
}
|
|
|
|
|
2016-09-13 07:43:29 +02:00
|
|
|
func (f *fKeyDestroyer) Read(b []byte) (int, error) {
|
|
|
|
if f.buf == nil {
|
|
|
|
all, err := ioutil.ReadAll(f.reader)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2016-06-02 23:07:51 +02:00
|
|
|
|
2016-09-14 06:46:58 +02:00
|
|
|
f.buf = bytes.NewBuffer(f.rgx.ReplaceAll(all, []byte{}))
|
2016-06-02 23:07:51 +02:00
|
|
|
}
|
|
|
|
|
2016-09-13 07:43:29 +02:00
|
|
|
return f.buf.Read(b)
|
2016-06-02 23:07:51 +02:00
|
|
|
}
|
2016-09-20 10:05:33 +02:00
|
|
|
|