Skip to content

Commit

Permalink
Merge pull request #28 from Chia-Network/fix/michael.taylor/database-…
Browse files Browse the repository at this point in the history
…connection

Fix/michael.taylor/database connection
  • Loading branch information
MichaelTaylor3D authored Dec 7, 2021
2 parents 12223d0 + 69f279a commit 6ba5853
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var path = require('path');

module.exports = {
config: path.resolve('src', 'config', 'config.json'),
'migrations-path': path.resolve('migrations'),
'models-path': path.resolve('src', 'models'),
'seeders-path': path.resolve('seeders'),
};
14 changes: 11 additions & 3 deletions migrations/20211207145446-staging.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Staging', {
await queryInterface.createTable('Stagings', {
id: {
allowNull: false,
autoIncrement: true,
Expand All @@ -19,12 +19,20 @@ module.exports = {
type: Sequelize.STRING,
},
data: {
type: Sequelize.STRING,
type: Sequelize.STRING(10000),
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
},
});
},

down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Staging');
await queryInterface.dropTable('Stagings');
},
};
2 changes: 1 addition & 1 deletion src/config/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"app_database": {
"development": {
"dialect": "sqlite",
"storage": "./data.sqlite3"
},
Expand Down
7 changes: 3 additions & 4 deletions src/models/database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Sequelize } from 'sequelize';
export const sequelize = new Sequelize('database', 'username', 'password', {
dialect: 'sqlite',
storage: './data.sqlite3',
});
import config from '../config/config.json';

export const sequelize = new Sequelize(config['development']);
3 changes: 2 additions & 1 deletion src/models/staging/staging.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ Staging.init(
table: Sequelize.STRING,
action: Sequelize.STRING,
data: Sequelize.STRING,
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE,
},
{
sequelize,
modelName: 'Staging',
timestamps: false,
},
);

Expand Down
4 changes: 4 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import express from 'express';
import bodyParser from 'body-parser';
import { V1Router } from './v1';
import { sequelize } from '../models/database';

const app = express();

app.use(express.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.use('/v1', V1Router);

sequelize.authenticate().then(() => console.log('Connected to database'));

export default app;

0 comments on commit 6ba5853

Please sign in to comment.