-
Notifications
You must be signed in to change notification settings - Fork 0
Base de datos y migraciones
Alejandro Brunacci edited this page Oct 27, 2016
·
1 revision
DB_STRING = 'postgresql://bitsonbot:bitson@localhost:5432/bitsonbot'
# DB CONFIGURATION
logger.debug("Starting DB Connection")
engine = create_engine(DB_STRING)
Base = declarative_base(bind=engine)
Session = sessionmaker(bind=engine)
session = Session()
Ex: models/users.py
#! /usr/bin/env python
# -*- coding:utf-8 -*-
# Standard lib Imports
# Third Party Imports
from sqlalchemy import Column, String, Integer, Boolean
# BITSON Imports
from utils import Base
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True, index=True)
username = Column(String(200))
telegram_id = Column(String(100)
private_chat = Column(String(100)
admin = Column(Boolean)
banned = Column(Boolean)
alembic init --template generic ./migrations
Agregar a los imports:
import importdir
importdir.do('models', globals())
from utils import Base # Importamos Base para poder obtener la metadata
Cambiamos la siguiente linea
tarteg_metadata = Base.metadata
PYTHONPATH=. alembic revision --autogenerate -m "mensaje"
PYTHONPATH=. alembic upgrade head