Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
survey
Commits
af301853
Commit
af301853
authored
Nov 14, 2022
by
Yoon, Daeki
😅
Browse files
마이그레이션 추가
parent
b4873b7c
Changes
4
Show whitespace changes
Inline
Side-by-side
docs/overview.md
View file @
af301853
...
@@ -25,3 +25,19 @@ useEffect(() => {
...
@@ -25,3 +25,19 @@ useEffect(() => {
**SurveyLayout**
**SurveyLayout**
`SurveysLayout context`
로부터
`surveys`
를 받아
`surveyId`
에 해당하는
`survey`
상태를 뽑아내서
`Outlet context`
로
`survey`
를 내보냅니다.
`SurveysLayout context`
로부터
`surveys`
를 받아
`surveyId`
에 해당하는
`survey`
상태를 뽑아내서
`Outlet context`
로
`survey`
를 내보냅니다.
## 데이터베이스 초기화
### admin user와 role 생성
```
bash
npx ts-node src
\m
igrations
\c
reate-tables.ts
```
### role 테이블 초기화
기존의 roles 테이블 항목들을 모두 삭제하고 새로 생성합니다.
```
bash
npx ts-node src
\m
igrations
\c
reate-roles.ts
```
src/migrations/create-roles.ts
0 → 100644
View file @
af301853
import
mongoose
from
"
mongoose
"
;
import
{
mongoUri
}
from
"
../config
"
;
import
{
userDb
,
roleDb
}
from
"
../db
"
;
import
{
Role
,
User
}
from
"
../models
"
;
mongoose
.
connect
(
mongoUri
)
.
then
(
async
(
mongoose
)
=>
{
// 기존 역할들 모두 삭제
console
.
log
(
"
clearing existing all roles
"
);
await
Role
.
deleteMany
();
// 기본 역할 생성
console
.
log
(
"
creating default roles
"
);
const
roles
=
[
{
name
:
"
admin
"
,
priority
:
1
},
{
name
:
"
manager
"
,
priority
:
10
},
{
name
:
"
staff
"
,
priority
:
100
},
{
name
:
"
user
"
,
priority
:
1000
},
{
name
:
"
guest
"
,
priority
:
10000
},
];
await
Role
.
create
(
roles
);
mongoose
.
connection
.
close
();
})
.
catch
((
err
)
=>
console
.
log
(
"
mongoose connection error:
"
,
err
));
export
default
{};
src/migrations/create-tables.ts
0 → 100644
View file @
af301853
import
mongoose
from
"
mongoose
"
;
import
{
mongoUri
}
from
"
../config
"
;
import
{
userDb
,
roleDb
}
from
"
../db
"
;
import
{
Role
,
User
}
from
"
../models
"
;
mongoose
.
connect
(
mongoUri
)
.
then
(
async
(
mongoose
)
=>
{
// 기존 역할들 모두 삭제
// console.log("clearing existing all roles");
// await Role.deleteMany();
// 기본 역할 생성
console
.
log
(
"
creating default roles
"
);
const
roles
=
[
{
name
:
"
admin
"
,
priority
:
1
},
{
name
:
"
manager
"
,
priority
:
10
},
{
name
:
"
staff
"
,
priority
:
100
},
{
name
:
"
user
"
,
priority
:
1000
},
{
name
:
"
guest
"
,
priority
:
10000
},
];
// await Role.create(roles);
const
asyncRoles
=
roles
.
map
(
async
(
role
)
=>
{
console
.
log
(
"
creating role:
"
,
role
.
name
,
"
...
"
);
await
Role
.
findOneAndUpdate
({
name
:
role
.
name
},
role
,
{
upsert
:
true
});
});
await
Promise
.
all
(
asyncRoles
);
// 기존 사용자 모두 삭제
// console.log("clearing all users");
// await User.deleteMany();
// admin 유저 생성
console
.
log
(
"
creating the admin user
"
);
const
adminRole
=
await
roleDb
.
findRoleByName
(
"
admin
"
);
if
(
!
adminRole
)
{
throw
new
Error
(
"
admin role not exists
"
);
}
const
adminUser
=
{
email
:
"
admin@example.com
"
,
password
:
"
asdfasdf
"
,
name
:
"
Administrator
"
,
role
:
adminRole
.
_id
,
};
await
User
.
findOneAndUpdate
({
email
:
adminUser
.
email
},
adminUser
,
{
upsert
:
true
,
});
mongoose
.
connection
.
close
();
})
.
catch
((
err
)
=>
console
.
log
(
"
mongoose connection error:
"
,
err
));
export
default
{};
src/migrations/create-users.ts
0 → 100644
View file @
af301853
import
mongoose
from
"
mongoose
"
;
import
{
mongoUri
}
from
"
../config
"
;
import
{
roleDb
,
userDb
}
from
"
../db
"
;
import
{
User
}
from
"
../models
"
;
mongoose
.
connect
(
mongoUri
)
.
then
(
async
(
mongoose
)
=>
{
// 기존 사용자 모두 삭제
console
.
log
(
"
clearing all users
"
);
await
User
.
deleteMany
();
// 기본 사용자 생성
console
.
log
(
"
creating the admin user
"
);
const
adminRole
=
await
roleDb
.
findRoleByName
(
"
admin
"
);
if
(
!
adminRole
)
{
throw
new
Error
(
"
admin role not exists
"
);
}
const
adminUser
=
{
email
:
"
admin@example.com
"
,
password
:
"
asdfasdf
"
,
name
:
"
Administrator
"
,
role
:
adminRole
.
_id
,
};
await
userDb
.
createUser
(
adminUser
);
mongoose
.
connection
.
close
();
})
.
catch
((
err
)
=>
console
.
log
(
"
mongoose connection error:
"
,
err
));
export
default
{};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment