Replace dev/schema.sql with Laravel migrations in the backend

Baseline migration reproduces the production dump byte-for-byte (verified via
mariadb-dump diff); creates are hasTable-guarded so prod only records it.
Drop stock Laravel migrations that contradict prod and Sanctum's bundled one.
This commit is contained in:
kurogeek committed 2026-10-15 11:06:06 +00:00
1 parent d38f9a1a83
commit abf482eeb0
14 files changed
+164 -394

No files matched your search

+10 -8
View File
@@ -29,10 +29,10 @@ usage() {
Usage: dev <command>
setup composer install both apps + init local MariaDB
db start|stop|status manage local MariaDB (data in .dev/mysql, port $DB_PORT); start applies dev/schema.sql
db start|stop|status manage local MariaDB (data in .dev/mysql, port $DB_PORT); start runs backend migrations
db shell mysql client on the local DB
db import <dump.sql> drop + recreate the DB from a production dump (schema + data)
db reset drop + recreate the DB with dev/schema.sql only (empty tables)
db reset drop + recreate the DB, then migrate (empty tables)
serve frontend php artisan serve -> http://127.0.0.1:$FRONTEND_PORT
serve backend php artisan serve -> http://127.0.0.1:$BACKEND_PORT
up db + both apps; Ctrl-C stops everything
@@ -64,6 +64,7 @@ db_start() {
db_init
if db_running; then
echo "db: already running (pid $(cat "$MYSQL_PID"))"
db_migrate
return
fi
# Ignore terminal Ctrl-C in the DB so `up` can shut it down cleanly after the app servers.
@@ -82,13 +83,14 @@ CREATE USER IF NOT EXISTS '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS';
GRANT ALL ON \`$DB_NAME\`.* TO '$DB_USER'@'127.0.0.1', '$DB_USER'@'localhost';
FLUSH PRIVILEGES;
SQL
db_apply_schema
db_migrate
echo "db: listening on 127.0.0.1:$DB_PORT (pid $(cat "$MYSQL_PID"))"
}
# Idempotent (CREATE TABLE IF NOT EXISTS), so safe on every start; a no-op once tables exist.
db_apply_schema() {
mariadb --socket="$MYSQL_SOCK" -uroot "$DB_NAME" <"$ROOT/dev/schema.sql"
# The schema lives in think-backend/database/migrations; `migrate` is a no-op once applied.
db_migrate() {
[ -f "$BACKEND/vendor/autoload.php" ] || composer_install
(cd "$BACKEND" && php artisan migrate --force --no-interaction)
}
db_recreate() {
@@ -124,8 +126,8 @@ db_import() {
db_reset() {
db_running || db_start
db_recreate
db_apply_schema
echo "db: reset to dev/schema.sql"
db_migrate
echo "db: reset to empty schema"
}
composer_install() {