@@ -68,14 +68,14 @@ func newRepository(r dbw.Reader, w dbw.Writer, opt ...Option) (*repository, erro
68
68
if w == nil {
69
69
return nil , fmt .Errorf ("%s: nil writer: %w" , op , ErrInvalidParameter )
70
70
}
71
- if _ , err := validateSchema (context .Background (), r ); err != nil {
72
- return nil , fmt .Errorf ("%s: %w" , op , err )
73
- }
74
71
opts := getOpts (opt ... )
75
72
if opts .withLimit == 0 {
76
73
// zero signals the defaults should be used.
77
74
opts .withLimit = defaultLimit
78
75
}
76
+ if _ , err := validateSchema (context .Background (), r , opts .withTableNamePrefix ); err != nil {
77
+ return nil , fmt .Errorf ("%s: %w" , op , err )
78
+ }
79
79
return & repository {
80
80
reader : r ,
81
81
writer : w ,
@@ -88,13 +88,15 @@ func newRepository(r dbw.Reader, w dbw.Writer, opt ...Option) (*repository, erro
88
88
// required migrations.Version
89
89
func (r * repository ) ValidateSchema (ctx context.Context ) (string , error ) {
90
90
const op = "kms.(repository).validateVersion"
91
- return validateSchema (ctx , r .reader )
91
+ return validateSchema (ctx , r .reader , r . tableNamePrefix )
92
92
}
93
93
94
- func validateSchema (ctx context.Context , r dbw.Reader ) (string , error ) {
94
+ func validateSchema (ctx context.Context , r dbw.Reader , tableNamePrefix string ) (string , error ) {
95
95
const op = "kms.validateSchema"
96
- var s schema
97
- if err := r .LookupWhere (ctx , & s , "1=1" , nil ); err != nil {
96
+ s := schema {
97
+ tableNamePrefix : tableNamePrefix ,
98
+ }
99
+ if err := r .LookupWhere (ctx , & s , "1=1" , nil , dbw .WithTable (s .TableName ())); err != nil {
98
100
return "" , fmt .Errorf ("%s: unable to get version: %w" , op , err )
99
101
}
100
102
if s .Version != migrations .Version {
0 commit comments