Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore:system user and events created by userid migrations #5612

Merged
merged 12 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/db/user-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class UserStore implements IUserStore {
return this.db(TABLE).where({
deleted_at: null,
is_service: false,
is_system: false,
});
}

Expand Down
21 changes: 21 additions & 0 deletions src/migrations/20231212094044-event-created-by-user-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

exports.up = function (db, callback) {
db.runSql(
`
ALTER TABLE events ADD COLUMN IF NOT EXISTS created_by_user_id INTEGER;
daveleek marked this conversation as resolved.
Show resolved Hide resolved
CREATE INDEX events_created_by_user_id_idx ON events(created_by_user_id);
`,
callback,
);
};

exports.down = function (db, callback) {
db.runSql(
`
DROP INDEX IF EXISTS events_created_by_user_id_idx;
ALTER TABLE events DROP COLUMN IF EXISTS created_by_user_id;
daveleek marked this conversation as resolved.
Show resolved Hide resolved
`,
callback,
);
};
24 changes: 24 additions & 0 deletions src/migrations/20231212094343-unleash-system-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

exports.up = function (db, callback) {
db.runSql(
`
ALTER TABLE users ADD COLUMN IF NOT EXISTS is_system BOOLEAN NOT NULL DEFAULT FALSE;
INSERT INTO users
(id, name, username, email, created_by, is_system)
VALUES
(-1337, 'Used by unleash internally for performing system actions that have no user', 'unleash_system_user', '[email protected]', -1337, true);
daveleek marked this conversation as resolved.
Show resolved Hide resolved
`,
callback,
);
};

exports.down = function (db, callback) {
db.runSql(
`
ALTER TABLE users DROP COLUMN IF EXISTS is_system;
DELETE FROM users WHERE id = -1337;
`,
callback,
);
};
Loading