MCPcopy
hub / github.com/pocketbase/pocketbase / registerMigrations

Method registerMigrations

plugins/jsvm/jsvm.go:183–234  ·  view source on GitHub ↗

registerMigrations registers the JS migrations loader.

()

Source from the content-addressed store, hash-verified

181
182// registerMigrations registers the JS migrations loader.
183func (p *plugin) registerMigrations() error {
184 // fetch all js migrations sorted by their filename
185 files, err := filesContent(p.config.MigrationsDir, p.config.MigrationsFilesPattern)
186 if err != nil {
187 return err
188 }
189
190 absHooksDir, err := filepath.Abs(p.config.HooksDir)
191 if err != nil {
192 return err
193 }
194
195 registry := new(require.Registry) // this can be shared by multiple runtimes
196 templateRegistry := template.NewRegistry()
197
198 for file, content := range files {
199 vm := goja.New()
200
201 registry.Enable(vm)
202 console.Enable(vm)
203 process.Enable(vm)
204 buffer.Enable(vm)
205
206 BindCore(vm)
207 BindDbx(vm)
208 BindSecurity(vm)
209 BindOS(vm)
210 BindFilepath(vm)
211 BindHTTP(vm)
212 BindFilesystem(vm)
213 BindForms(vm)
214 BindMails(vm)
215
216 vm.Set("$template", templateRegistry)
217 vm.Set("__hooks", absHooksDir)
218
219 vm.Set("migrate", func(up, down func(txApp core.App) error) {
220 core.AppMigrations.Register(up, down, file)
221 })
222
223 if p.config.OnInit != nil {
224 p.config.OnInit(vm)
225 }
226
227 _, err := vm.RunScript(defaultScriptPath, string(content))
228 if err != nil {
229 return fmt.Errorf("failed to run migration %s: %w", file, err)
230 }
231 }
232
233 return nil
234}
235
236// registerHooks registers the JS app hooks loader.
237func (p *plugin) registerHooks() error {

Callers 1

RegisterFunction · 0.95

Calls 13

NewRegistryFunction · 0.92
filesContentFunction · 0.85
BindCoreFunction · 0.85
BindDbxFunction · 0.85
BindSecurityFunction · 0.85
BindOSFunction · 0.85
BindFilepathFunction · 0.85
BindHTTPFunction · 0.85
BindFilesystemFunction · 0.85
BindFormsFunction · 0.85
BindMailsFunction · 0.85
SetMethod · 0.65

Tested by

no test coverage detected