mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-01 01:18:10 +02:00
fix: add migration
This commit is contained in:
parent
875fb7734c
commit
d73293c576
@ -29,6 +29,7 @@ import EnvironmentStore from './environment-store';
|
|||||||
import FeatureTagStore from './feature-tag-store';
|
import FeatureTagStore from './feature-tag-store';
|
||||||
import { FeatureEnvironmentStore } from './feature-environment-store';
|
import { FeatureEnvironmentStore } from './feature-environment-store';
|
||||||
import { ClientMetricsStoreV2 } from './client-metrics-store-v2';
|
import { ClientMetricsStoreV2 } from './client-metrics-store-v2';
|
||||||
|
import UserSplashStore from './user-splash-store';
|
||||||
|
|
||||||
export const createStores = (
|
export const createStores = (
|
||||||
config: IUnleashConfig,
|
config: IUnleashConfig,
|
||||||
@ -85,6 +86,7 @@ export const createStores = (
|
|||||||
eventBus,
|
eventBus,
|
||||||
getLogger,
|
getLogger,
|
||||||
),
|
),
|
||||||
|
userSplashStore: new UserSplashStore(db, eventBus, getLogger),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,10 +47,7 @@ export default class UserSplashStore implements IUserSplashStore {
|
|||||||
return userSplash.map(rowToField);
|
return userSplash.map(rowToField);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSplash(
|
async getSplash(userId: number, splashId: string): Promise<IUserSplash> {
|
||||||
userId: number,
|
|
||||||
splashId: string,
|
|
||||||
): Promise<IUserSplash> {
|
|
||||||
const userSplash = await this.db
|
const userSplash = await this.db
|
||||||
.table<IUserSplashTable>(TABLE)
|
.table<IUserSplashTable>(TABLE)
|
||||||
.select()
|
.select()
|
||||||
@ -92,10 +89,7 @@ export default class UserSplashStore implements IUserSplashStore {
|
|||||||
return present;
|
return present;
|
||||||
}
|
}
|
||||||
|
|
||||||
async get({
|
async get({ userId, splashId }: IUserSplashKey): Promise<IUserSplash> {
|
||||||
userId,
|
|
||||||
splashId,
|
|
||||||
}: IUserSplashKey): Promise<IUserSplash> {
|
|
||||||
return this.getSplash(userId, splashId);
|
return this.getSplash(userId, splashId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import { IUnleashServices } from '../../types/services';
|
|||||||
import UserService from '../../services/user-service';
|
import UserService from '../../services/user-service';
|
||||||
import SessionService from '../../services/session-service';
|
import SessionService from '../../services/session-service';
|
||||||
import UserFeedbackService from '../../services/user-feedback-service';
|
import UserFeedbackService from '../../services/user-feedback-service';
|
||||||
|
import UserSplashService from 'lib/services/user-splash-service';
|
||||||
|
|
||||||
interface IChangeUserRequest {
|
interface IChangeUserRequest {
|
||||||
password: string;
|
password: string;
|
||||||
@ -22,6 +23,8 @@ class UserController extends Controller {
|
|||||||
|
|
||||||
private sessionService: SessionService;
|
private sessionService: SessionService;
|
||||||
|
|
||||||
|
private userSplashService: UserSplashService;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
config: IUnleashConfig,
|
config: IUnleashConfig,
|
||||||
{
|
{
|
||||||
@ -29,12 +32,14 @@ class UserController extends Controller {
|
|||||||
userService,
|
userService,
|
||||||
sessionService,
|
sessionService,
|
||||||
userFeedbackService,
|
userFeedbackService,
|
||||||
|
userSplashService,
|
||||||
}: Pick<
|
}: Pick<
|
||||||
IUnleashServices,
|
IUnleashServices,
|
||||||
| 'accessService'
|
| 'accessService'
|
||||||
| 'userService'
|
| 'userService'
|
||||||
| 'sessionService'
|
| 'sessionService'
|
||||||
| 'userFeedbackService'
|
| 'userFeedbackService'
|
||||||
|
| 'userSplashService'
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
super(config);
|
super(config);
|
||||||
@ -57,6 +62,7 @@ class UserController extends Controller {
|
|||||||
const feedback = await this.userFeedbackService.getAllUserFeedback(
|
const feedback = await this.userFeedbackService.getAllUserFeedback(
|
||||||
user,
|
user,
|
||||||
);
|
);
|
||||||
|
//const splash = await this.userSplashService.getAllUserSplash(user);
|
||||||
|
|
||||||
// TODO: remove this line after we remove it from db.
|
// TODO: remove this line after we remove it from db.
|
||||||
delete user.permissions;
|
delete user.permissions;
|
||||||
|
@ -27,6 +27,7 @@ import FeatureToggleService from './feature-toggle-service';
|
|||||||
import EnvironmentService from './environment-service';
|
import EnvironmentService from './environment-service';
|
||||||
import FeatureTagService from './feature-tag-service';
|
import FeatureTagService from './feature-tag-service';
|
||||||
import ProjectHealthService from './project-health-service';
|
import ProjectHealthService from './project-health-service';
|
||||||
|
import UserSplashService from './user-splash-service';
|
||||||
|
|
||||||
export const createServices = (
|
export const createServices = (
|
||||||
stores: IUnleashStores,
|
stores: IUnleashStores,
|
||||||
@ -72,6 +73,7 @@ export const createServices = (
|
|||||||
accessService,
|
accessService,
|
||||||
featureToggleServiceV2,
|
featureToggleServiceV2,
|
||||||
);
|
);
|
||||||
|
const userSplashService = new UserSplashService(stores, config);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
accessService,
|
accessService,
|
||||||
@ -100,6 +102,7 @@ export const createServices = (
|
|||||||
userFeedbackService,
|
userFeedbackService,
|
||||||
featureTagService,
|
featureTagService,
|
||||||
projectHealthService,
|
projectHealthService,
|
||||||
|
userSplashService,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,14 +28,12 @@ export default class UserSplashService {
|
|||||||
return await this.userSplashStore.getAllUserSplashs(user.id);
|
return await this.userSplashStore.getAllUserSplashs(user.id);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSplash(
|
async getSplash(user_id: number, splash_id: string): Promise<IUserSplash> {
|
||||||
user_id: number,
|
|
||||||
splash_id: string,
|
|
||||||
): Promise<IUserSplash> {
|
|
||||||
return this.userSplashStore.getSplash(user_id, splash_id);
|
return this.userSplashStore.getSplash(user_id, splash_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import EnvironmentService from '../services/environment-service';
|
|||||||
import FeatureTagService from '../services/feature-tag-service';
|
import FeatureTagService from '../services/feature-tag-service';
|
||||||
import ProjectHealthService from '../services/project-health-service';
|
import ProjectHealthService from '../services/project-health-service';
|
||||||
import ClientMetricsServiceV2 from '../services/client-metrics/client-metrics-service-v2';
|
import ClientMetricsServiceV2 from '../services/client-metrics/client-metrics-service-v2';
|
||||||
|
import UserSplashService from '../services/user-splash-service';
|
||||||
|
|
||||||
export interface IUnleashServices {
|
export interface IUnleashServices {
|
||||||
accessService: AccessService;
|
accessService: AccessService;
|
||||||
@ -51,4 +52,5 @@ export interface IUnleashServices {
|
|||||||
userFeedbackService: UserFeedbackService;
|
userFeedbackService: UserFeedbackService;
|
||||||
userService: UserService;
|
userService: UserService;
|
||||||
versionService: VersionService;
|
versionService: VersionService;
|
||||||
|
userSplashService: UserSplashService;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Store } from './store';
|
import { Store } from './store';
|
||||||
|
|
||||||
export interface IUserSplash {
|
export interface IUserSplash {
|
||||||
seen?: boolean;
|
seen: boolean;
|
||||||
splashId: string;
|
splashId: string;
|
||||||
userId: number;
|
userId: number;
|
||||||
}
|
}
|
||||||
@ -11,8 +11,7 @@ export interface IUserSplashKey {
|
|||||||
splashId: string;
|
splashId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IUserSplashStore
|
export interface IUserSplashStore extends Store<IUserSplash, IUserSplashKey> {
|
||||||
extends Store<IUserSplash, IUserSplashKey> {
|
|
||||||
getAllUserSplashs(userId: number): Promise<IUserSplash[]>;
|
getAllUserSplashs(userId: number): Promise<IUserSplash[]>;
|
||||||
getSplash(userId: number, splashId: string): Promise<IUserSplash>;
|
getSplash(userId: number, splashId: string): Promise<IUserSplash>;
|
||||||
updateSplash(splash: IUserSplash): Promise<IUserSplash>;
|
updateSplash(splash: IUserSplash): Promise<IUserSplash>;
|
||||||
|
@ -8,18 +8,17 @@ exports.up = function (db, cb) {
|
|||||||
splash_id TEXT,
|
splash_id TEXT,
|
||||||
seen BOOLEAN NOT NULL DEFAULT false,
|
seen BOOLEAN NOT NULL DEFAULT false,
|
||||||
PRIMARY KEY (user_id, splash_id));
|
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,
|
cb,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.down = function (db, cb) {
|
exports.down = function (db, cb) {
|
||||||
db.runSql(
|
db.runSql(
|
||||||
`
|
`
|
||||||
DROP INDEX user_splash_user_id_idx;
|
DROP INDEX user_splash_user_id_idx;
|
||||||
DROP TABLE user_splash;
|
DROP TABLE user_splash;
|
||||||
`,
|
`,
|
||||||
cb,
|
cb,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
15
src/migrations/20211109103930-add-splash-entry-for-users.js
Normal file
15
src/migrations/20211109103930-add-splash-entry-for-users.js
Normal 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);
|
||||||
|
};
|
@ -8,7 +8,7 @@ process.nextTick(async () => {
|
|||||||
createConfig({
|
createConfig({
|
||||||
db: {
|
db: {
|
||||||
user: 'unleash_user',
|
user: 'unleash_user',
|
||||||
password: 'some_password',
|
password: 'passord',
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 5432,
|
port: 5432,
|
||||||
database: 'unleash',
|
database: 'unleash',
|
||||||
|
65
src/test/fixtures/fake-user-splash-store.ts
vendored
Normal file
65
src/test/fixtures/fake-user-splash-store.ts
vendored
Normal 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 {}
|
||||||
|
}
|
2
src/test/fixtures/store.ts
vendored
2
src/test/fixtures/store.ts
vendored
@ -24,6 +24,7 @@ import FakeFeatureTypeStore from './fake-feature-type-store';
|
|||||||
import FakeResetTokenStore from './fake-reset-token-store';
|
import FakeResetTokenStore from './fake-reset-token-store';
|
||||||
import FakeFeatureToggleClientStore from './fake-feature-toggle-client-store';
|
import FakeFeatureToggleClientStore from './fake-feature-toggle-client-store';
|
||||||
import FakeClientMetricsStoreV2 from './fake-client-metrics-store-v2';
|
import FakeClientMetricsStoreV2 from './fake-client-metrics-store-v2';
|
||||||
|
import FakeUserSplashStore from './fake-user-splash-store';
|
||||||
|
|
||||||
const createStores: () => IUnleashStores = () => {
|
const createStores: () => IUnleashStores = () => {
|
||||||
const db = {
|
const db = {
|
||||||
@ -59,6 +60,7 @@ const createStores: () => IUnleashStores = () => {
|
|||||||
featureTypeStore: new FakeFeatureTypeStore(),
|
featureTypeStore: new FakeFeatureTypeStore(),
|
||||||
resetTokenStore: new FakeResetTokenStore(),
|
resetTokenStore: new FakeResetTokenStore(),
|
||||||
sessionStore: new FakeSessionStore(),
|
sessionStore: new FakeSessionStore(),
|
||||||
|
userSplashStore: new FakeUserSplashStore(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user