Skip to content

Database migrations

You never import SQL by hand. bs_core creates and upgrades the schema itself on boot.

  • Migration files are in bs_core/sql/, numbered (001_core_schema.sql up to 035_faction_jobs.sql right now).
  • On start bs_core runs every file in its list that isn’t recorded yet, in order, and records it in the bs_migrations table with a checksum. A file never runs twice.
  • The console prints what it applied on that boot.
  • A few resources make their own small tables with CREATE TABLE IF NOT EXISTS on start (for example bs_tester and bs_config). Nothing to do for those either.
FileAdds
029_vehicle_world.sqlWorld vehicles, missing parts
030_user_language.sqlbs_users.language
031_building.sqlbs_build_pieces, bs_build_bases, moves old structures to factions
032_crafting.sqlStation queues, traps, offline refunds, recycler points
033_medical.sqlbs_character_medical: injuries, infection, sickness, blood
034_base_flags.sqlSafezone and outpost flags, declared raids
035_faction_jobs.sqlJob members, the board, scores, job picks, garage work
045_darkzone.sqlDark Zone (1.1.0)
046_building_v2.sqlBuilding v2: power, generators, flags (1.1.0)
047_faction_emblems.sqlFaction emblems (1.1.0)
048_backpack_refresh.sqlBackpack items renamed, contents kept (1.1.0)
  1. Make the next number: bs_core/sql/036_my_change.sql.
  2. Write it so it’s safe on a database that already has data. Add columns with defaults, don’t drop things people still use.
  3. Add the filename to the list in bs_core/server/sv_migrations.lua (M.files). The list is hardcoded. A file that isn’t in it is silently never run.
  4. Restart the server (restarting bs_core alone kicks everyone).

Before an update that adds migrations, back up. On Windows:

Terminal window
powershell -ExecutionPolicy Bypass -File .\tools\Backup-Database.ps1

See Updating & database for restore and moving characters between servers.