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-13 07:43:29 +02:00
|
|
|
var rgxPGFkey = regexp.MustCompile(`(?m)(?s)^ALTER TABLE ONLY.*?ADD CONSTRAINT.*?FOREIGN KEY.*?;\n`)
|
|
|
|
var rgxMySQLkey = regexp.MustCompile(`(?m)((,\n)?\s+CONSTRAINT.*?FOREIGN KEY.*?\n)+`)
|
2016-06-02 23:07:51 +02:00
|
|
|
|
2016-09-13 07:43:29 +02:00
|
|
|
func newFKeyDestroyer(reader io.Reader) io.Reader {
|
|
|
|
return &fKeyDestroyer{
|
|
|
|
reader: reader,
|
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-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-13 07:43:29 +02:00
|
|
|
f.buf = bytes.NewBuffer(rgxMySQLkey.ReplaceAll(rgxPGFkey.ReplaceAll(all, []byte{}), []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
|
|
|
}
|