To automate DB schema versioning you can use scommons-websql-migrations
library together with sbt-scommons-plugin
First, set the scommonsBundlesFileFilter
sbt
build project
setting:
import scommons.sbtplugin.ScommonsPlugin.autoImport._
project(...)
.settings(
...,
scommonsBundlesFileFilter := "*.sql",
...
)
Then add your SQL
migrations scripts:
This setup will automatically generate single bundle.json
file
during the build with the all SQL scripts content inside.
You can read generated bundle.json
file from the code:
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scommons.websql.migrations.WebSqlMigrationBundle
@js.native
@JSImport("./scommons/websql/migrations/bundle.json", JSImport.Namespace)
object TestMigrationsBundle extends WebSqlMigrationBundle
This is how you can run migrations at the start of your app:
import scommons.websql.migrations.WebSqlMigrations
val migrations = new WebSqlMigrations(db)
migrations.runBundle(TestMigrationsBundle)