fix: db
This commit is contained in:
Executable
+77
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env bash
|
||||
# Delete photo files under storage/app/private/c2 older than a cutoff (mtime).
|
||||
# Deletes as it finds — does not collect the full list first.
|
||||
# Default cutoff: 2026-09-15 00:00:00 (keeps the 15th and later).
|
||||
#
|
||||
# ./scripts/prune-c2-photos-before.sh
|
||||
# ./scripts/prune-c2-photos-before.sh --execute
|
||||
# BEFORE=2026-09-15 ./scripts/prune-c2-photos-before.sh --execute
|
||||
|
||||
set -u
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
if [ -z "${APP_ROOT:-}" ]; then
|
||||
APP_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
fi
|
||||
BEFORE="${BEFORE:-2026-09-15}"
|
||||
CUTOFF="${BEFORE} 00:00:00"
|
||||
EXECUTE=0
|
||||
if [ "${1:-}" = "--execute" ]; then
|
||||
EXECUTE=1
|
||||
fi
|
||||
|
||||
PHOTOS="${APP_ROOT}/storage/app/private/c2/photos"
|
||||
PREVIEWS="${APP_ROOT}/storage/app/private/c2/photo-previews"
|
||||
|
||||
if [ ! -d "$PHOTOS" ]; then
|
||||
echo "ERROR: missing $PHOTOS" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo "=== prune c2 photos by mtime ==="
|
||||
echo "app : $APP_ROOT"
|
||||
echo "cutoff : before $CUTOFF"
|
||||
echo "mode : $([ "$EXECUTE" -eq 1 ] && echo EXECUTE || echo DRY-RUN)"
|
||||
echo "hint : deletes while scanning; a line every 200 files"
|
||||
echo
|
||||
|
||||
prune_dir() {
|
||||
local dir="$1"
|
||||
local label="$2"
|
||||
if [ ! -d "$dir" ]; then
|
||||
echo "$label: skip (missing)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "$label: $dir"
|
||||
if [ "$EXECUTE" -eq 1 ]; then
|
||||
find "$dir" -type f ! -newermt "$CUTOFF" -print -delete
|
||||
else
|
||||
find "$dir" -type f ! -newermt "$CUTOFF" -print
|
||||
fi | awk -v label="$label" '
|
||||
{
|
||||
n++
|
||||
if (n <= 5 || n % 200 == 0) {
|
||||
print " " label " " n " " $0
|
||||
fflush()
|
||||
}
|
||||
}
|
||||
END {
|
||||
print " " label " total=" (n + 0)
|
||||
fflush()
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
prune_dir "$PHOTOS" "photos"
|
||||
prune_dir "$PREVIEWS" "previews"
|
||||
|
||||
if [ "$EXECUTE" -eq 1 ]; then
|
||||
find "$PHOTOS" -mindepth 1 -type d -empty -delete 2>/dev/null || true
|
||||
if [ -d "$PREVIEWS" ]; then
|
||||
find "$PREVIEWS" -mindepth 1 -type d -empty -delete 2>/dev/null || true
|
||||
fi
|
||||
echo "done (deleted as found)"
|
||||
else
|
||||
echo "dry-run only; pass --execute to delete"
|
||||
fi
|
||||
@@ -0,0 +1,34 @@
|
||||
-- Only devices.* times. Dashboard / daily-report device counts use created_at
|
||||
-- (and updated_at for「活跃」). Do not touch photos / visits / other tables.
|
||||
--
|
||||
-- 1) 备份 devices
|
||||
-- 2) 把 @cutoff 改成切时区那一刻
|
||||
-- 3) 先预览,再 START TRANSACTION … COMMIT
|
||||
-- 4) 提交后:php artisan coruna:daily-stats --all
|
||||
|
||||
SET time_zone = '+08:00';
|
||||
SET @cutoff = '2026-09-16 14:00:00'; -- TODO: 改成实际切时区的时间
|
||||
|
||||
SELECT 'created_at' AS col, COUNT(*) AS n, MIN(created_at) AS mn, MAX(created_at) AS mx
|
||||
FROM devices WHERE created_at IS NOT NULL AND created_at < @cutoff
|
||||
UNION ALL SELECT 'updated_at', COUNT(*), MIN(updated_at), MAX(updated_at)
|
||||
FROM devices WHERE updated_at IS NOT NULL AND updated_at < @cutoff
|
||||
UNION ALL SELECT 'first_seen_at', COUNT(*), MIN(first_seen_at), MAX(first_seen_at)
|
||||
FROM devices WHERE first_seen_at IS NOT NULL AND first_seen_at < @cutoff
|
||||
UNION ALL SELECT 'last_seen_at', COUNT(*), MIN(last_seen_at), MAX(last_seen_at)
|
||||
FROM devices WHERE last_seen_at IS NOT NULL AND last_seen_at < @cutoff;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
UPDATE devices SET created_at = DATE_SUB(created_at, INTERVAL 8 HOUR)
|
||||
WHERE created_at IS NOT NULL AND created_at < @cutoff;
|
||||
UPDATE devices SET updated_at = DATE_SUB(updated_at, INTERVAL 8 HOUR)
|
||||
WHERE updated_at IS NOT NULL AND updated_at < @cutoff;
|
||||
UPDATE devices SET first_seen_at = DATE_SUB(first_seen_at, INTERVAL 8 HOUR)
|
||||
WHERE first_seen_at IS NOT NULL AND first_seen_at < @cutoff;
|
||||
UPDATE devices SET last_seen_at = DATE_SUB(last_seen_at, INTERVAL 8 HOUR)
|
||||
WHERE last_seen_at IS NOT NULL AND last_seen_at < @cutoff;
|
||||
|
||||
-- 后台看一台改时区前的设备,时间对了再 COMMIT
|
||||
COMMIT;
|
||||
-- ROLLBACK;
|
||||
Reference in New Issue
Block a user