Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fahrtenbuch
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWP WS21_22 - Fahrtenbuch
Team Einhorn
fahrtenbuch
Commits
41ec6276
Commit
41ec6276
authored
3 years ago
by
alrwasheda
Browse files
Options
Downloads
Patches
Plain Diff
unnecessary log eliminated + log sugar
parent
851d2613
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/src/db/index.ts
+15
-10
15 additions, 10 deletions
server/src/db/index.ts
server/src/db/showAllDBs.ts
+1
-1
1 addition, 1 deletion
server/src/db/showAllDBs.ts
server/src/db/showDBTables.ts
+1
-1
1 addition, 1 deletion
server/src/db/showDBTables.ts
with
17 additions
and
12 deletions
server/src/db/index.ts
+
15
−
10
View file @
41ec6276
...
...
@@ -2,9 +2,9 @@ import { Client } from "pg";
import
{
Dialect
,
Sequelize
}
from
"
sequelize
"
;
import
envVars
from
"
../config
"
;
import
{
initBoat
}
from
"
./models/Boat
"
;
import
{
initCheckIn
}
from
"
./models/CheckIn
"
;
import
{
initCustomer
}
from
"
./models/Customer
"
;
import
{
initWorker
}
from
"
./models/Worker
"
;
import
{
initCheckIn
}
from
"
./models/CheckIn
"
;
import
{
initCustomer
}
from
"
./models/Customer
"
;
import
{
initWorker
}
from
"
./models/Worker
"
;
const
initializeDatabase
=
async
()
=>
{
const
client
=
new
Client
({
...
...
@@ -15,22 +15,27 @@ const initializeDatabase = async () => {
// https://stackoverflow.com/questions/18389124/simulate-create-database-if-not-exists-for-postgresql
await
client
.
connect
();
console
.
log
(
envVars
.
DB_NAME
);
console
.
log
(
`DB Name:
${
envVars
.
DB_NAME
}
`
);
const
isDatabaseExistingQuery
=
await
client
.
query
(
`SELECT * FROM pg_database WHERE datname='
${
envVars
.
DB_NAME
}
'`
);
console
.
log
(
isDatabaseExistingQuery
);
//
console.log(isDatabaseExistingQuery);
const
isDatabaseExisting
=
isDatabaseExistingQuery
.
rowCount
===
1
;
if
(
!
isDatabaseExisting
)
{
await
client
.
query
(
`CREATE DATABASE "
${
envVars
.
DB_NAME
}
"`
);
}
client
.
end
();
const
sequelize
=
new
Sequelize
(
envVars
.
DB_NAME
,
envVars
.
DB_USER
,
envVars
.
DB_PASSWORD
,
{
host
:
envVars
.
DB_HOST
,
dialect
:
envVars
.
DB_DRIVER
as
Dialect
,
logging
:
false
,
});
const
sequelize
=
new
Sequelize
(
envVars
.
DB_NAME
,
envVars
.
DB_USER
,
envVars
.
DB_PASSWORD
,
{
host
:
envVars
.
DB_HOST
,
dialect
:
envVars
.
DB_DRIVER
as
Dialect
,
logging
:
false
,
}
);
await
initBoat
(
sequelize
);
await
initCheckIn
(
sequelize
);
...
...
This diff is collapsed.
Click to expand it.
server/src/db/showAllDBs.ts
+
1
−
1
View file @
41ec6276
...
...
@@ -7,7 +7,7 @@ const showAllDBs = async (sequelizeConnection: Sequelize) => {
console
.
log
(
"
----------Found Databases----------
\n
"
,
res
,
"
\n
--------------------
\n
"
"
\n
--------------------
---------------
\n
"
);
});
};
...
...
This diff is collapsed.
Click to expand it.
server/src/db/showDBTables.ts
+
1
−
1
View file @
41ec6276
...
...
@@ -11,7 +11,7 @@ const showTables = async (sequelizeConnection: Sequelize) => {
)
.
then
((
res
)
=>
{
//------------------------------------------------then
console
.
log
(
`TABELS IN
${
envVars
.
DB_NAME
}
\n
-------------\n
`
,
res
);
console
.
log
(
`
-----
TABELS IN
${
envVars
.
DB_NAME
}
------\n`
,
res
,
"
\n
----------------------
-------------
\n
"
);
});
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment