GithubHelp home page GithubHelp logo

How to migrate DB? about pygmy HOT 3 CLOSED

mzch avatar mzch commented on June 15, 2024
How to migrate DB?

from pygmy.

Comments (3)

mzch avatar mzch commented on June 15, 2024 1

I created .py file of alembic and executed it successfully. Thanks! :)

"""create table

Revision ID: e7d7571bbcd3
Revises:
Create Date: 2020-01-09 19:44:30.527606

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'e7d7571bbcd3'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    op.create_table(
      'users',
      sa.Column('id', sa.Integer, autoincrement=True, primary_key=True),
      sa.Column('email', sa.String(120), unique=True, index=True),
      sa.Column('f_name', sa.String(30), nullable=False),
      sa.Column('m_name', sa.String(30), default=''),
      sa.Column('l_name', sa.String(30), nullable=False),
      sa.Column('password', sa.String(300), nullable=False),
      sa.Column('is_deleted', sa.Boolean, default=False),
      sa.Column('created_at', sa.TIMESTAMP(timezone=False), server_default=sa.func.current_timestamp()),
      sa.Column('updated_at', sa.TIMESTAMP(timezone=False), onupdate=sa.func.current_timestamp())
    )

    op.create_table(
      'link',
      sa.Column('id', sa.Integer, autoincrement=True, primary_key=True),
      sa.Column('long_url', sa.Unicode(1000), index=True),
      sa.Column('protocol', sa.String(10), default='http://'),
      sa.Column('domain', sa.String(300), ),
      sa.Column('long_url_hash', sa.BigInteger, index=True),
      sa.Column('short_code', sa.Unicode(6), unique=True, index=True, default=None),
      sa.Column('description', sa.String(1000), default=None),
      sa.Column('owner', sa.Integer, default=None),
      sa.Column('secret_key', sa.String(12), default=''),
      sa.Column('expire_after', sa.Integer, default=None),
      sa.Column('is_default', sa.Boolean, default=False),
      sa.Column('is_protected', sa.Boolean, default=False),
      sa.Column('is_disabled', sa.Boolean, default=False),
      sa.Column('is_custom', sa.Boolean, default=False),
      sa.Column('created_at', sa.TIMESTAMP(timezone=False), server_default=sa.func.current_timestamp()),
      sa.Column('updated_at', sa.TIMESTAMP(timezone=False), onupdate=sa.func.current_timestamp())
    )

    op.create_table(
      'clickmeta',
      sa.Column('id', sa.Integer, autoincrement=True, primary_key=True),
      sa.Column('link_id', sa.Integer, sa.ForeignKey('link.id')),
      sa.Column('country', sa.String(5), nullable=True),
      sa.Column('referrer', sa.String(100), nullable=True),
      sa.Column('created_at', sa.TIMESTAMP(timezone=False), server_default=sa.func.current_timestamp())
    )

def downgrade():
    op.drop_table('user', schema='production'),
    op.drop_table('clickmeta', schema='production'),
    op.drop_table('link', schema='production')

p.s.
I renamed user table to users.

from pygmy.

amitt001 avatar amitt001 commented on June 15, 2024

Hi,
Yes, currently it doesn't. Migrations through Alembic(https://alembic.sqlalchemy.org/en/latest/) was something that was planned but I didn't get to it. You can use it.

from pygmy.

mzch avatar mzch commented on June 15, 2024

Mm...I can't understand how to use alembic in order to migrate db...

from pygmy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.