mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
a very much PoC
This commit is contained in:
parent
b190970df2
commit
a3fb81d88b
@ -110,6 +110,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@electric-sql/pglite": "^0.2.12",
|
||||||
"@slack/web-api": "^7.3.4",
|
"@slack/web-api": "^7.3.4",
|
||||||
"@wesleytodd/openapi": "^1.1.0",
|
"@wesleytodd/openapi": "^1.1.0",
|
||||||
"ajv": "^8.12.0",
|
"ajv": "^8.12.0",
|
||||||
@ -143,6 +144,7 @@
|
|||||||
"json-schema-to-ts": "2.12.0",
|
"json-schema-to-ts": "2.12.0",
|
||||||
"json2csv": "^5.0.7",
|
"json2csv": "^5.0.7",
|
||||||
"knex": "^3.1.0",
|
"knex": "^3.1.0",
|
||||||
|
"knex-pglite": "^0.9.7",
|
||||||
"lodash.get": "^4.4.2",
|
"lodash.get": "^4.4.2",
|
||||||
"lodash.groupby": "^4.6.0",
|
"lodash.groupby": "^4.6.0",
|
||||||
"lodash.sortby": "^4.7.0",
|
"lodash.sortby": "^4.7.0",
|
||||||
|
3791
schema.sql
Normal file
3791
schema.sql
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,19 +1,21 @@
|
|||||||
import { knex, type Knex } from 'knex';
|
import { knex, type Knex } from 'knex';
|
||||||
|
import ClientPgLite from 'knex-pglite';
|
||||||
import type { IUnleashConfig } from '../types/option';
|
import type { IUnleashConfig } from '../types/option';
|
||||||
|
import type { PGlite } from '@electric-sql/pglite';
|
||||||
|
|
||||||
export function createDb({
|
export function createDb(
|
||||||
db,
|
{ db, getLogger }: Pick<IUnleashConfig, 'db' | 'getLogger'>,
|
||||||
getLogger,
|
pg?: PGlite,
|
||||||
}: Pick<IUnleashConfig, 'db' | 'getLogger'>): Knex {
|
): Knex {
|
||||||
const logger = getLogger('db-pool.js');
|
const logger = getLogger('db-pool.js');
|
||||||
return knex({
|
return knex({
|
||||||
client: 'pg',
|
client: ClientPgLite,
|
||||||
version: db.version,
|
dialect: 'postgres',
|
||||||
connection: {
|
connection: {
|
||||||
...db,
|
//@ts-ignore
|
||||||
application_name: db.applicationName,
|
// pglite: pg || new PGlite(),
|
||||||
|
filename: '/tmp/unleash.db',
|
||||||
},
|
},
|
||||||
pool: db.pool,
|
|
||||||
searchPath: db.schema,
|
searchPath: db.schema,
|
||||||
asyncStackTraces: true,
|
asyncStackTraces: true,
|
||||||
log: {
|
log: {
|
||||||
|
@ -49,6 +49,7 @@ const rowToUser = (row) => {
|
|||||||
if (!row) {
|
if (!row) {
|
||||||
throw new NotFoundError('No user found');
|
throw new NotFoundError('No user found');
|
||||||
}
|
}
|
||||||
|
console.log(row);
|
||||||
return new User({
|
return new User({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
name: emptify(row.name),
|
name: emptify(row.name),
|
||||||
@ -180,7 +181,7 @@ class UserStore implements IUserStore {
|
|||||||
|
|
||||||
async getByQuery(idQuery: IUserLookup): Promise<User> {
|
async getByQuery(idQuery: IUserLookup): Promise<User> {
|
||||||
const row = await this.buildSelectUser(idQuery).first(USER_COLUMNS);
|
const row = await this.buildSelectUser(idQuery).first(USER_COLUMNS);
|
||||||
return rowToUser(row);
|
return rowToUser(row.rows[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(id: number): Promise<void> {
|
async delete(id: number): Promise<void> {
|
||||||
@ -203,7 +204,9 @@ class UserStore implements IUserStore {
|
|||||||
throw new NotFoundError('User not found');
|
throw new NotFoundError('User not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return item.password_hash;
|
console.log(item);
|
||||||
|
|
||||||
|
return item.rows[0].password_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setPasswordHash(
|
async setPasswordHash(
|
||||||
|
@ -89,12 +89,13 @@ export const scheduleServices = async (
|
|||||||
'announceUnannounced',
|
'announceUnannounced',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
schedulerService.schedule(
|
schedulerService.schedule(
|
||||||
projectService.statusJob.bind(projectService),
|
projectService.statusJob.bind(projectService),
|
||||||
hoursToMilliseconds(24),
|
hoursToMilliseconds(24),
|
||||||
'statusJob',
|
'statusJob',
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
schedulerService.schedule(
|
schedulerService.schedule(
|
||||||
projectHealthService.setHealthRating.bind(projectHealthService),
|
projectHealthService.setHealthRating.bind(projectHealthService),
|
||||||
hoursToMilliseconds(1),
|
hoursToMilliseconds(1),
|
||||||
|
@ -35,6 +35,7 @@ import { Db } from './db/db';
|
|||||||
import { defaultLockKey, defaultTimeout, withDbLock } from './util/db-lock';
|
import { defaultLockKey, defaultTimeout, withDbLock } from './util/db-lock';
|
||||||
import { scheduleServices } from './features/scheduler/schedule-services';
|
import { scheduleServices } from './features/scheduler/schedule-services';
|
||||||
import { compareAndLogPostgresVersion } from './util/postgres-version-checker';
|
import { compareAndLogPostgresVersion } from './util/postgres-version-checker';
|
||||||
|
import { createPg } from '../pglite';
|
||||||
|
|
||||||
async function createApp(
|
async function createApp(
|
||||||
config: IUnleashConfig,
|
config: IUnleashConfig,
|
||||||
@ -43,7 +44,10 @@ async function createApp(
|
|||||||
// Database dependencies (stateful)
|
// Database dependencies (stateful)
|
||||||
const logger = config.getLogger('server-impl.js');
|
const logger = config.getLogger('server-impl.js');
|
||||||
const serverVersion = config.enterpriseVersion ?? version;
|
const serverVersion = config.enterpriseVersion ?? version;
|
||||||
const db = createDb(config);
|
|
||||||
|
const pg = await createPg();
|
||||||
|
const db = createDb(config, pg);
|
||||||
|
|
||||||
const stores = createStores(config, db);
|
const stores = createStores(config, db);
|
||||||
await compareAndLogPostgresVersion(config, stores.settingStore);
|
await compareAndLogPostgresVersion(config, stores.settingStore);
|
||||||
const services = createServices(stores, config, db);
|
const services = createServices(stores, config, db);
|
||||||
|
@ -33,7 +33,6 @@ import {
|
|||||||
ALL_PROJECTS,
|
ALL_PROJECTS,
|
||||||
CUSTOM_PROJECT_ROLE_TYPE,
|
CUSTOM_PROJECT_ROLE_TYPE,
|
||||||
CUSTOM_ROOT_ROLE_TYPE,
|
CUSTOM_ROOT_ROLE_TYPE,
|
||||||
ROOT_ROLE_TYPES,
|
|
||||||
} from '../util/constants';
|
} from '../util/constants';
|
||||||
import { DEFAULT_PROJECT } from '../types/project';
|
import { DEFAULT_PROJECT } from '../types/project';
|
||||||
import InvalidOperationError from '../error/invalid-operation-error';
|
import InvalidOperationError from '../error/invalid-operation-error';
|
||||||
@ -433,11 +432,12 @@ export class AccessService {
|
|||||||
const newRootRole = await this.resolveRootRole(role);
|
const newRootRole = await this.resolveRootRole(role);
|
||||||
if (newRootRole) {
|
if (newRootRole) {
|
||||||
try {
|
try {
|
||||||
|
/*
|
||||||
await this.store.removeRolesOfTypeForUser(
|
await this.store.removeRolesOfTypeForUser(
|
||||||
userId,
|
userId,
|
||||||
ROOT_ROLE_TYPES,
|
ROOT_ROLE_TYPES,
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
await this.store.addUserToRole(
|
await this.store.addUserToRole(
|
||||||
userId,
|
userId,
|
||||||
newRootRole.id,
|
newRootRole.id,
|
||||||
|
@ -185,6 +185,7 @@ class UserService {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
`Unable to create default user '${username}'`,
|
`Unable to create default user '${username}'`,
|
||||||
|
e,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -392,10 +393,14 @@ class UserService {
|
|||||||
: { username: usernameOrEmail };
|
: { username: usernameOrEmail };
|
||||||
|
|
||||||
let user: IUser | undefined, passwordHash: string | undefined;
|
let user: IUser | undefined, passwordHash: string | undefined;
|
||||||
|
console.log('idQuery', idQuery);
|
||||||
try {
|
try {
|
||||||
user = await this.store.getByQuery(idQuery);
|
user = await this.store.getByQuery(idQuery);
|
||||||
passwordHash = await this.store.getPasswordHash(user.id);
|
passwordHash = await this.store.getPasswordHash(user.id);
|
||||||
} catch (error) {}
|
console.log(passwordHash);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
if (user && passwordHash) {
|
if (user && passwordHash) {
|
||||||
const match = await bcrypt.compare(password, passwordHash);
|
const match = await bcrypt.compare(password, passwordHash);
|
||||||
if (match) {
|
if (match) {
|
||||||
|
4938
src/lib/sql-migrate.ts
Normal file
4938
src/lib/sql-migrate.ts
Normal file
File diff suppressed because it is too large
Load Diff
4954
src/pglite.ts
Normal file
4954
src/pglite.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,7 @@ process.nextTick(async () => {
|
|||||||
schema: process.env.UNLEASH_DATABASE_SCHEMA,
|
schema: process.env.UNLEASH_DATABASE_SCHEMA,
|
||||||
ssl: false,
|
ssl: false,
|
||||||
applicationName: 'unleash',
|
applicationName: 'unleash',
|
||||||
|
disableMigration: true,
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
enableRequestLogger: true,
|
enableRequestLogger: true,
|
||||||
|
21
yarn.lock
21
yarn.lock
@ -967,6 +967,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"@electric-sql/pglite@npm:^0.2.12, @electric-sql/pglite@npm:^0.2.6":
|
||||||
|
version: 0.2.12
|
||||||
|
resolution: "@electric-sql/pglite@npm:0.2.12"
|
||||||
|
checksum: 10c0/28414b26ec73c81eab649fe45b291e63db29f7ec780b47edabb16759c5b6ba66fa90134073c4c17fd78b96179f23ea66f78eedd3cc1cc355a4b062d525b847bb
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"@ewoudenberg/difflib@npm:0.1.0":
|
"@ewoudenberg/difflib@npm:0.1.0":
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
resolution: "@ewoudenberg/difflib@npm:0.1.0"
|
resolution: "@ewoudenberg/difflib@npm:0.1.0"
|
||||||
@ -6150,7 +6157,17 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"knex@npm:3, knex@npm:^3.1.0":
|
"knex-pglite@npm:^0.9.7":
|
||||||
|
version: 0.9.7
|
||||||
|
resolution: "knex-pglite@npm:0.9.7"
|
||||||
|
dependencies:
|
||||||
|
"@electric-sql/pglite": "npm:^0.2.6"
|
||||||
|
knex: "npm:3.1.0"
|
||||||
|
checksum: 10c0/892cc52bdafdb44c70aac70c8e44a320c65c21250dd1d1e09e264685514b03940285c3f8f135b16956b995fc9725e8f6bedd9d7019ead814f58e5463657e6174
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
|
"knex@npm:3, knex@npm:3.1.0, knex@npm:^3.1.0":
|
||||||
version: 3.1.0
|
version: 3.1.0
|
||||||
resolution: "knex@npm:3.1.0"
|
resolution: "knex@npm:3.1.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -9334,6 +9351,7 @@ __metadata:
|
|||||||
"@babel/core": "npm:7.25.8"
|
"@babel/core": "npm:7.25.8"
|
||||||
"@biomejs/biome": "npm:^1.8.3"
|
"@biomejs/biome": "npm:^1.8.3"
|
||||||
"@cyclonedx/yarn-plugin-cyclonedx": "npm:^1.0.0-rc.7"
|
"@cyclonedx/yarn-plugin-cyclonedx": "npm:^1.0.0-rc.7"
|
||||||
|
"@electric-sql/pglite": "npm:^0.2.12"
|
||||||
"@slack/web-api": "npm:^7.3.4"
|
"@slack/web-api": "npm:^7.3.4"
|
||||||
"@swc/core": "npm:1.7.36"
|
"@swc/core": "npm:1.7.36"
|
||||||
"@swc/jest": "npm:0.2.36"
|
"@swc/jest": "npm:0.2.36"
|
||||||
@ -9402,6 +9420,7 @@ __metadata:
|
|||||||
json-schema-to-ts: "npm:2.12.0"
|
json-schema-to-ts: "npm:2.12.0"
|
||||||
json2csv: "npm:^5.0.7"
|
json2csv: "npm:^5.0.7"
|
||||||
knex: "npm:^3.1.0"
|
knex: "npm:^3.1.0"
|
||||||
|
knex-pglite: "npm:^0.9.7"
|
||||||
lint-staged: "npm:15.2.10"
|
lint-staged: "npm:15.2.10"
|
||||||
lodash.get: "npm:^4.4.2"
|
lodash.get: "npm:^4.4.2"
|
||||||
lodash.groupby: "npm:^4.6.0"
|
lodash.groupby: "npm:^4.6.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user