Skip to content

Commit

Permalink
Sync auto de models com o Postgre pelo Sequelize
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaellima8 committed Feb 4, 2017
1 parent afd4b26 commit 3cfb502
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
USER postgres
RUN /etc/init.d/postgresql start &&\
createdb api -O postgres
RUN /etc/init.d/postgresql start &&\
createdb api -O postgres &&\
psql -c "ALTER USER postgres WITH PASSWORD 'pgroot'" &&\
psql -d api -c 'CREATE TABLE "Users" (
id serial NOT NULL,
"name" character varying (255),
"email" character varying (255),
"password" character varying(255),
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL
);'
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
EXPOSE 5432
Expand All @@ -23,5 +32,4 @@ RUN npm install

COPY . /usr/src/ts-api
EXPOSE 4000

CMD npm run watch
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* gulp
* PostgreSQL
* Sequelize
* Docker

## Getting Started
Clone this repo:
Expand All @@ -29,5 +30,4 @@ Tests:
npm run test
```


License: MIT
2 changes: 1 addition & 1 deletion server/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as bcrypt from 'bcrypt';
export default function(sequelize, DataTypes) {
var User = sequelize.define('User', {
id: {
type: DataTypes.STRING,
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
Expand Down
1 change: 0 additions & 1 deletion server/modules/User/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default class UserRoutes {
}

index(req:Request, res:Response) {
console.log('oi')
return UserCtlr.getAll(req, res);
}

Expand Down
12 changes: 7 additions & 5 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ import * as http from 'http';
import * as debug from 'debug';
import Api from './api/api';
import {errorHandlerApi} from './api/errorHandlerApi';

var models = require('./models');
debug('ts-api:server');

const port = normalizePort(process.env.PORT || 3000);

Api.set('port', port);
const server = http.createServer(Api);

server.listen(port);

server.on('error', onError);
server.on('listening', listen);
models.sequelize.sync().then(() => {
server.listen(port);
server.on('error', onError);
server.on('listening', listen);
});

Api.use(errorHandlerApi);

function listen():void {
let address = server.address();
let bind = (typeof address === 'string') ? `Address ${address}` : `Port ${address.port}`;
debug(`Server is runnig on port ${bind}`);
console.log(`Server is runnig on port ${bind}`);
}

function onError(error: NodeJS.ErrnoException): void {
Expand Down
8 changes: 0 additions & 8 deletions server/sql_script/userTable

This file was deleted.

0 comments on commit 3cfb502

Please sign in to comment.