1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-09 11:14:29 +02:00
unleash.unleash/src/migrations/20240116154700-unleash-admin-token-user.js
Gastón Fournier 04e55831e3
chore: add another system user for admin tokens (#5915)
## About the changes
This admin token user will help us differentiate actions performed by
the system from actions performed with an admin token.

Events created with an admin token should have the id of this user as
createdByUserId property and the username of the token used as the
createdBy property. i.e.
```json
{
  "id": 11,
  "type": "pat-created",
  "createdBy": "admin-token",
  "createdAt": "2024-01-16T13:16:27.887Z",
  "createdByUserId": -42,
  "data": {
    "description": "admin-pat",
    "expiresAt": "2024-02-15T13:16:25.586Z",
    "secret": "***",
    "userId": 1
  },
  "preData": null,
  "tags": [],
  "featureName": null,
  "project": null,
  "environment": null
}
```
2024-01-16 19:28:36 +01:00

23 lines
451 B
JavaScript

'use strict';
exports.up = function (db, callback) {
db.runSql(
`
INSERT INTO users
(id, name, username, created_by_user_id, is_system)
VALUES
(-42, 'Unleash Admin Token User', 'unleash_admin_token', -1337, true);
`,
callback,
);
};
exports.down = function (db, callback) {
db.runSql(
`
DELETE FROM users WHERE id = -42;
`,
callback,
);
};