手工修复数据
Get the ID
First you need to find out the ID of the drive or charge:
- Drive
- Charge
- Open the
Drives
dashboard and click on the start date of the drive. - The URL will contain the drive ID, for example
&var-drive_id=9999
.
- Open the
Charges
dashboard and click on the start date of the charge. - The URL will contain the charge id, for example
&var-charging_process_id=9999
.
Terminate a drive or charge
If for some reason a drive or charge hasn't been fully recorded, for example due to a bug or an unexpected restart, you can terminate it manually. Among other things, this assigns an end date to the drive/charge.
Replace 9999
with the actual ID then run the command while the TeslaMate container is running:
- Drive
- Charge
docker-compose exec teslamate bin/teslamate rpc \
"TeslaMate.Repo.get!(TeslaMate.Log.Drive, 9999) |> TeslaMate.Log.close_drive()"
docker-compose exec teslamate bin/teslamate rpc \
"TeslaMate.Repo.get!(TeslaMate.Log.ChargingProcess, 9999) |> TeslaMate.Log.complete_charging_process()"
Delete a drive or charge
If for some reason a drive or charge was recorded incorrectly, you can delete it.
Attach to the running database container:
docker-compose exec database psql teslamate teslamate
noteIf you get the error
No such service: database
, update your docker-compose.yml or usedb
instead ofdatabase
in the above command.Afterwards replace
9999
with the actual ID then run the query:- Drive
- Charge
DELETE FROM drives WHERE id = 9999;
DELETE FROM charging_processes WHERE id = 9999;
Remove a vehicle from the database
NOTE: Always backup your data before performing any database changes.
- Connect to your TeslaMate database
- Identify the right car ID in the database to remove
SELECT id, vin FROM cars;
- Based upon the output, run the following command replacing
num
with the ID from the previous command.
DELETE FROM cars WHERE id = num;
DELETE FROM car_settings WHERE id = num;
DELETE FROM charging_processes WHERE car_id = num;
DELETE from charges WHERE charging_process_id in (select id from charging_processes where car_id = num);
DELETE FROM drives WHERE car_id = num;
DELETE FROM positions WHERE car_id = num;
DELETE FROM states WHERE car_id = num;
DELETE FROM updates WHERE car_id = num;