This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 755
Add default postgres schema so that it can be changed #824
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
appleboy
approved these changes
Jan 9, 2018
will be a basis to resolve go-gitea/gitea#2755 |
examples: func init() {
xorm.DefaultPostgresSchema = "mcs"
}
// NewEngine initializes a new xorm.Engine
func NewEngine() (err error) {
if err = SetEngine(); err != nil {
return err
}
if err = x.Ping(); err != nil {
return err
}
row, err := x.Exec(`SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'mcs';`)
if err != nil {
return err
}
affects, err := row.RowsAffected()
if affects == 0 {
if _, err = x.Exec(`CREATE SCHEMA "mcs"`); err != nil {
return err
}
}
if _, err = x.Exec(`SET SEARCH_PATH = mcs, pg_catalog`); err != nil {
return err
}
m := migrate.New(x, migrate.DefaultOptions, migrations)
if err = m.Migrate(); err != nil {
return fmt.Errorf("migrate: %v", err)
}
if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
return fmt.Errorf("sync database struct error: %v", err)
}
return nil
} |
Codecov Report
@@ Coverage Diff @@
## master #824 +/- ##
==========================================
+ Coverage 53.2% 53.22% +0.02%
==========================================
Files 39 39
Lines 7323 7324 +1
==========================================
+ Hits 3896 3898 +2
Misses 2931 2931
+ Partials 496 495 -1
Continue to review full report at Codecov.
|
marefr
added a commit
to grafana/grafana
that referenced
this pull request
May 29, 2019
xorm introduced some changes in go-xorm/xorm#824 and go-xorm/xorm#876 which by default will use public as the postgres schema and this was a breaking change compared to before. Grafana has implemented a custom postgres dialect so above changes wasn't a problem here. However, Grafana's custom database migration was using xorm dialect to check if the migration table exists or not. For those using a custom search_path (schema) in postgres configured on server, database or user level the migration table check would not find the migration table since it was looking in public schema due to xorm changes above. This had the consequence that Grafana's database migration failed the second time since migration had already run migrations in another schema. This change will make xorm use an empty default schema for postgres and by that mimic the functionality of how it was functioning before xorm's changes above.
marefr
added a commit
to grafana/grafana
that referenced
this pull request
Jun 3, 2019
xorm introduced some changes in go-xorm/xorm#824 and go-xorm/xorm#876 which by default will use public as the postgres schema and this was a breaking change compared to before. Grafana has implemented a custom postgres dialect so above changes wasn't a problem here. However, Grafana's custom database migration was using xorm dialect to check if the migration table exists or not. For those using a custom search_path (schema) in postgres configured on server, database or user level the migration table check would not find the migration table since it was looking in public schema due to xorm changes above. This had the consequence that Grafana's database migration failed the second time since migration had already run migrations in another schema. This change will make xorm use an empty default schema for postgres and by that mimic the functionality of how it was functioning before xorm's changes above. Fixes #16720 Co-Authored-By: Carl Bergquist <carl@grafana.com>
aocenas
pushed a commit
to grafana/grafana
that referenced
this pull request
Jun 5, 2019
xorm introduced some changes in go-xorm/xorm#824 and go-xorm/xorm#876 which by default will use public as the postgres schema and this was a breaking change compared to before. Grafana has implemented a custom postgres dialect so above changes wasn't a problem here. However, Grafana's custom database migration was using xorm dialect to check if the migration table exists or not. For those using a custom search_path (schema) in postgres configured on server, database or user level the migration table check would not find the migration table since it was looking in public schema due to xorm changes above. This had the consequence that Grafana's database migration failed the second time since migration had already run migrations in another schema. This change will make xorm use an empty default schema for postgres and by that mimic the functionality of how it was functioning before xorm's changes above. Fixes #16720 Co-Authored-By: Carl Bergquist <carl@grafana.com> (cherry picked from commit b7a9533)
aocenas
pushed a commit
to grafana/grafana
that referenced
this pull request
Jun 5, 2019
xorm introduced some changes in go-xorm/xorm#824 and go-xorm/xorm#876 which by default will use public as the postgres schema and this was a breaking change compared to before. Grafana has implemented a custom postgres dialect so above changes wasn't a problem here. However, Grafana's custom database migration was using xorm dialect to check if the migration table exists or not. For those using a custom search_path (schema) in postgres configured on server, database or user level the migration table check would not find the migration table since it was looking in public schema due to xorm changes above. This had the consequence that Grafana's database migration failed the second time since migration had already run migrations in another schema. This change will make xorm use an empty default schema for postgres and by that mimic the functionality of how it was functioning before xorm's changes above. Fixes #16720 Co-Authored-By: Carl Bergquist <carl@grafana.com> (cherry picked from commit b7a9533)
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.