added example .env
This commit is contained in:
7
.env
Normal file
7
.env
Normal file
@@ -0,0 +1,7 @@
|
||||
PG_HOST=db
|
||||
PG_PORT=5432
|
||||
PG_USER=postgres
|
||||
PG_PASSWORD=changeme
|
||||
PG_DATABASE=webchat
|
||||
SESSION_SECRET=changeme
|
||||
JWT_SECRET=changeme
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
node_modules/
|
||||
.idea
|
||||
package-lock.json
|
||||
.env
|
||||
package-lock.json
|
||||
@@ -15,24 +15,33 @@ db.connect()
|
||||
.catch((err) => console.log('Error on connecting to database: ', err));
|
||||
|
||||
async function createTables() {
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS accounts (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(255) UNIQUE NOT NULL,
|
||||
password VARCHAR(255) NOT NULL
|
||||
)
|
||||
`);
|
||||
try {
|
||||
// Create accounts table
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS accounts (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(255) UNIQUE NOT NULL,
|
||||
password VARCHAR(255) NOT NULL
|
||||
)
|
||||
`);
|
||||
|
||||
// Create messages table
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id SERIAL PRIMARY KEY,
|
||||
content TEXT NOT NULL,
|
||||
username VARCHAR(50) NOT NULL,
|
||||
recipient VARCHAR(255) NOT NULL
|
||||
)
|
||||
`);
|
||||
// Create messages table
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id SERIAL PRIMARY KEY,
|
||||
content TEXT NOT NULL,
|
||||
username VARCHAR(50) NOT NULL,
|
||||
recipient VARCHAR(255) NOT NULL
|
||||
)
|
||||
`);
|
||||
|
||||
console.log('Tables created successfully');
|
||||
} catch (err) {
|
||||
console.error('Error creating tables:', err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
createTables()
|
||||
.catch((err) => {
|
||||
console.error('Error creating tables:', err);
|
||||
|
||||
Reference in New Issue
Block a user