# Stations to Locations Migration

The legacy system stored clocking points in a `stations` table. The new schema replaces this with a `locations` table that optionally references `companies` via `company_id`.

## Migration Steps

1. Ensure the `locations` table exists with at least the columns `id`, `name`, `latitude`, `longitude`, `company_id`, `isDeleted` and `updatedAt`.
2. Copy existing station records into `locations`, mapping each station to the correct company. If all stations belong to a single company you can supply that ID directly.

```sql
INSERT INTO locations (name, latitude, longitude, company_id)
SELECT s.name, s.latitude, s.longitude, 1 -- replace 1 with your company id
FROM stations s;
```

If you maintain a mapping table of station to company, join it during the insert:

```sql
INSERT INTO locations (name, latitude, longitude, company_id)
SELECT s.name, s.latitude, s.longitude, m.company_id
FROM stations s
JOIN station_company_map m ON m.station_id = s.id;
```

3. Update foreign keys or reference columns in your application from `station_id` to `location_id` where applicable.
4. Once validation is complete, drop the old `stations` table.
