1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

fix: add migration

This commit is contained in:
Fredrik Oseberg 2021-11-09 11:52:02 +01:00
parent 875fb7734c
commit d73293c576
12 changed files with 107 additions and 22 deletions

View File

@ -29,6 +29,7 @@ import EnvironmentStore from './environment-store';
import FeatureTagStore from './feature-tag-store';
import { FeatureEnvironmentStore } from './feature-environment-store';
import { ClientMetricsStoreV2 } from './client-metrics-store-v2';
import UserSplashStore from './user-splash-store';
export const createStores = (
config: IUnleashConfig,
@ -85,6 +86,7 @@ export const createStores = (
eventBus,
getLogger,
),
userSplashStore: new UserSplashStore(db, eventBus, getLogger),
};
};

View File

@ -47,10 +47,7 @@ export default class UserSplashStore implements IUserSplashStore {
return userSplash.map(rowToField);
}
async getSplash(
userId: number,
splashId: string,
): Promise<IUserSplash> {
async getSplash(userId: number, splashId: string): Promise<IUserSplash> {
const userSplash = await this.db
.table<IUserSplashTable>(TABLE)
.select()
@ -92,10 +89,7 @@ export default class UserSplashStore implements IUserSplashStore {
return present;
}
async get({
userId,
splashId,
}: IUserSplashKey): Promise<IUserSplash> {
async get({ userId, splashId }: IUserSplashKey): Promise<IUserSplash> {
return this.getSplash(userId, splashId);
}

View File

@ -7,6 +7,7 @@ import { IUnleashServices } from '../../types/services';
import UserService from '../../services/user-service';
import SessionService from '../../services/session-service';
import UserFeedbackService from '../../services/user-feedback-service';
import UserSplashService from 'lib/services/user-splash-service';
interface IChangeUserRequest {
password: string;
@ -22,6 +23,8 @@ class UserController extends Controller {
private sessionService: SessionService;
private userSplashService: UserSplashService;
constructor(
config: IUnleashConfig,
{
@ -29,12 +32,14 @@ class UserController extends Controller {
userService,
sessionService,
userFeedbackService,
userSplashService,
}: Pick<
IUnleashServices,
| 'accessService'
| 'userService'
| 'sessionService'
| 'userFeedbackService'
| 'userSplashService'
>,
) {
super(config);
@ -57,6 +62,7 @@ class UserController extends Controller {
const feedback = await this.userFeedbackService.getAllUserFeedback(
user,
);
//const splash = await this.userSplashService.getAllUserSplash(user);
// TODO: remove this line after we remove it from db.
delete user.permissions;

View File

@ -27,6 +27,7 @@ import FeatureToggleService from './feature-toggle-service';
import EnvironmentService from './environment-service';
import FeatureTagService from './feature-tag-service';
import ProjectHealthService from './project-health-service';
import UserSplashService from './user-splash-service';
export const createServices = (
stores: IUnleashStores,
@ -72,6 +73,7 @@ export const createServices = (
accessService,
featureToggleServiceV2,
);
const userSplashService = new UserSplashService(stores, config);
return {
accessService,
@ -100,6 +102,7 @@ export const createServices = (
userFeedbackService,
featureTagService,
projectHealthService,
userSplashService,
};
};

View File

@ -28,14 +28,12 @@ export default class UserSplashService {
return await this.userSplashStore.getAllUserSplashs(user.id);
} catch (err) {
this.logger.error(err);
return [];
}
}
async getSplash(
user_id: number,
splash_id: string,
): Promise<IUserSplash> {
async getSplash(user_id: number, splash_id: string): Promise<IUserSplash> {
return this.userSplashStore.getSplash(user_id, splash_id);
}

View File

@ -23,6 +23,7 @@ import EnvironmentService from '../services/environment-service';
import FeatureTagService from '../services/feature-tag-service';
import ProjectHealthService from '../services/project-health-service';
import ClientMetricsServiceV2 from '../services/client-metrics/client-metrics-service-v2';
import UserSplashService from '../services/user-splash-service';
export interface IUnleashServices {
accessService: AccessService;
@ -51,4 +52,5 @@ export interface IUnleashServices {
userFeedbackService: UserFeedbackService;
userService: UserService;
versionService: VersionService;
userSplashService: UserSplashService;
}

View File

@ -1,7 +1,7 @@
import { Store } from './store';
export interface IUserSplash {
seen?: boolean;
seen: boolean;
splashId: string;
userId: number;
}
@ -11,8 +11,7 @@ export interface IUserSplashKey {
splashId: string;
}
export interface IUserSplashStore
extends Store<IUserSplash, IUserSplashKey> {
export interface IUserSplashStore extends Store<IUserSplash, IUserSplashKey> {
getAllUserSplashs(userId: number): Promise<IUserSplash[]>;
getSplash(userId: number, splashId: string): Promise<IUserSplash>;
updateSplash(splash: IUserSplash): Promise<IUserSplash>;

View File

@ -8,18 +8,17 @@ exports.up = function (db, cb) {
splash_id TEXT,
seen BOOLEAN NOT NULL DEFAULT false,
PRIMARY KEY (user_id, splash_id));
CREATE INDEX user_splash_user_id_idx ON user_splash (user_id);
);`,
CREATE INDEX user_splash_user_id_idx ON user_splash (user_id);`,
cb,
);
};
exports.down = function (db, cb) {
db.runSql(
`
db.runSql(
`
DROP INDEX user_splash_user_id_idx;
DROP TABLE user_splash;
`,
cb,
);
cb,
);
};

View File

@ -0,0 +1,15 @@
exports.up = function (db, cb) {
db.runSql(`SELECT * FROM users`, (err, results) => {
results.rows.forEach((user) => {
db.runSql(
`INSERT INTO user_splash(splash_id, user_id, seen) VALUES (?, ?, ?)`,
['environments', user.id, false],
);
});
cb();
});
};
exports.down = function (db, cb) {
db.runSql('DELETE FROM user_splash', cb);
};

View File

@ -8,7 +8,7 @@ process.nextTick(async () => {
createConfig({
db: {
user: 'unleash_user',
password: 'some_password',
password: 'passord',
host: 'localhost',
port: 5432,
database: 'unleash',

View File

@ -0,0 +1,65 @@
import {
IUserSplashKey,
IUserSplash,
IUserSplashStore,
} from 'lib/types/stores/user-splash-store';
export default class FakeUserSplashStore implements IUserSplashStore {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getAllUserSplashs(userId: number): Promise<IUserSplash[]> {
return Promise.resolve([]);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getSplash(userId: number, splashId: string): Promise<IUserSplash> {
return Promise.resolve({ seen: false, userId: 123, splashId: 'env' });
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
updateSplash(splash: IUserSplash): Promise<IUserSplash> {
return Promise.resolve({ seen: false, userId: 123, splashId: 'env' });
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
exists(key: IUserSplashKey): Promise<boolean> {
return Promise.resolve(false);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
get(key: IUserSplashKey): Promise<IUserSplash> {
return Promise.resolve(undefined);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getAll(): Promise<IUserSplash[]> {
return Promise.resolve([]);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getAllUserFeedback(userId: number): Promise<IUserSplash[]> {
return Promise.resolve([]);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getFeedback(userId: number, feedbackId: string): Promise<IUserSplash> {
return Promise.resolve(undefined);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
updateFeedback(feedback: IUserSplash): Promise<IUserSplash> {
return Promise.resolve(undefined);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
delete(key: IUserSplashKey): Promise<void> {
return Promise.resolve(undefined);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
deleteAll(): Promise<void> {
return Promise.resolve(undefined);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
destroy(): void {}
}

View File

@ -24,6 +24,7 @@ import FakeFeatureTypeStore from './fake-feature-type-store';
import FakeResetTokenStore from './fake-reset-token-store';
import FakeFeatureToggleClientStore from './fake-feature-toggle-client-store';
import FakeClientMetricsStoreV2 from './fake-client-metrics-store-v2';
import FakeUserSplashStore from './fake-user-splash-store';
const createStores: () => IUnleashStores = () => {
const db = {
@ -59,6 +60,7 @@ const createStores: () => IUnleashStores = () => {
featureTypeStore: new FakeFeatureTypeStore(),
resetTokenStore: new FakeResetTokenStore(),
sessionStore: new FakeSessionStore(),
userSplashStore: new FakeUserSplashStore(),
};
};