aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/installer.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-12 17:53:50 +0100
committerChocobozzz <me@florianbigard.com>2017-12-13 16:50:33 +0100
commit3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch)
treee5ca358287fca6ecacce83defcf23af1e8e9f419 /server/initializers/installer.ts
parentc893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff)
downloadPeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip
Move models to typescript-sequelize
Diffstat (limited to 'server/initializers/installer.ts')
-rw-r--r--server/initializers/installer.ts25
1 files changed, 13 insertions, 12 deletions
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts
index 954516057..5452743b6 100644
--- a/server/initializers/installer.ts
+++ b/server/initializers/installer.ts
@@ -1,16 +1,17 @@
1import * as passwordGenerator from 'password-generator' 1import * as passwordGenerator from 'password-generator'
2import { UserRole } from '../../shared' 2import { UserRole } from '../../shared'
3import { logger, mkdirpPromise, rimrafPromise } from '../helpers' 3import { createPrivateAndPublicKeys, logger, mkdirpPromise, rimrafPromise } from '../helpers'
4import { createUserAccountAndChannel } from '../lib' 4import { createLocalAccountWithoutKeys, createUserAccountAndChannel } from '../lib'
5import { createLocalAccountWithoutKeys } from '../lib/user' 5import { UserModel } from '../models/account/user'
6import { ApplicationModel } from '../models/application/application'
7import { OAuthClientModel } from '../models/oauth/oauth-client'
6import { applicationExist, clientsExist, usersExist } from './checker' 8import { applicationExist, clientsExist, usersExist } from './checker'
7import { CACHE, CONFIG, LAST_MIGRATION_VERSION, SERVER_ACCOUNT_NAME } from './constants' 9import { CACHE, CONFIG, LAST_MIGRATION_VERSION, SERVER_ACCOUNT_NAME } from './constants'
8import { database as db } from './database' 10import { sequelizeTypescript } from './database'
9import { createPrivateAndPublicKeys } from '../helpers/peertube-crypto'
10 11
11async function installApplication () { 12async function installApplication () {
12 try { 13 try {
13 await db.sequelize.sync() 14 await sequelizeTypescript.sync()
14 await removeCacheDirectories() 15 await removeCacheDirectories()
15 await createDirectoriesIfNotExist() 16 await createDirectoriesIfNotExist()
16 await createApplicationIfNotExist() 17 await createApplicationIfNotExist()
@@ -64,7 +65,7 @@ function createDirectoriesIfNotExist () {
64} 65}
65 66
66async function createOAuthClientIfNotExist () { 67async function createOAuthClientIfNotExist () {
67 const exist = await clientsExist(db.OAuthClient) 68 const exist = await clientsExist()
68 // Nothing to do, clients already exist 69 // Nothing to do, clients already exist
69 if (exist === true) return undefined 70 if (exist === true) return undefined
70 71
@@ -72,7 +73,7 @@ async function createOAuthClientIfNotExist () {
72 73
73 const id = passwordGenerator(32, false, /[a-z0-9]/) 74 const id = passwordGenerator(32, false, /[a-z0-9]/)
74 const secret = passwordGenerator(32, false, /[a-zA-Z0-9]/) 75 const secret = passwordGenerator(32, false, /[a-zA-Z0-9]/)
75 const client = db.OAuthClient.build({ 76 const client = new OAuthClientModel({
76 clientId: id, 77 clientId: id,
77 clientSecret: secret, 78 clientSecret: secret,
78 grants: [ 'password', 'refresh_token' ], 79 grants: [ 'password', 'refresh_token' ],
@@ -87,7 +88,7 @@ async function createOAuthClientIfNotExist () {
87} 88}
88 89
89async function createOAuthAdminIfNotExist () { 90async function createOAuthAdminIfNotExist () {
90 const exist = await usersExist(db.User) 91 const exist = await usersExist()
91 // Nothing to do, users already exist 92 // Nothing to do, users already exist
92 if (exist === true) return undefined 93 if (exist === true) return undefined
93 94
@@ -120,7 +121,7 @@ async function createOAuthAdminIfNotExist () {
120 role, 121 role,
121 videoQuota: -1 122 videoQuota: -1
122 } 123 }
123 const user = db.User.build(userData) 124 const user = new UserModel(userData)
124 125
125 await createUserAccountAndChannel(user, validatePassword) 126 await createUserAccountAndChannel(user, validatePassword)
126 logger.info('Username: ' + username) 127 logger.info('Username: ' + username)
@@ -128,12 +129,12 @@ async function createOAuthAdminIfNotExist () {
128} 129}
129 130
130async function createApplicationIfNotExist () { 131async function createApplicationIfNotExist () {
131 const exist = await applicationExist(db.Application) 132 const exist = await applicationExist()
132 // Nothing to do, application already exist 133 // Nothing to do, application already exist
133 if (exist === true) return undefined 134 if (exist === true) return undefined
134 135
135 logger.info('Creating Application table.') 136 logger.info('Creating Application table.')
136 const applicationInstance = await db.Application.create({ migrationVersion: LAST_MIGRATION_VERSION }) 137 const applicationInstance = await ApplicationModel.create({ migrationVersion: LAST_MIGRATION_VERSION })
137 138
138 logger.info('Creating application account.') 139 logger.info('Creating application account.')
139 140