feat: draft version

This commit is contained in:
2021-01-03 15:10:47 +03:00
parent f003ed21cd
commit 884bc0aa97
19 changed files with 494 additions and 0 deletions

4
db_repo/README Normal file
View File

@@ -0,0 +1,4 @@
This is a database migration repository.
More information at
http://code.google.com/p/sqlalchemy-migrate/

0
db_repo/__init__.py Normal file
View File

5
db_repo/manage.py Normal file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env python
from migrate.versioning.shell import main
if __name__ == '__main__':
main(debug='False')

25
db_repo/migrate.cfg Normal file
View File

@@ -0,0 +1,25 @@
[db_settings]
# Used to identify which repository this database is versioned under.
# You can use the name of your project.
repository_id=assets-bot work table
# The name of the database table used to track the schema version.
# This name shouldn't already be used by your project.
# If this is changed once a database is under version control, you'll need to
# change the table name in each database too.
version_table=migrate_version
# When committing a change script, Migrate will attempt to generate the
# sql for all supported databases; normally, if one of them fails - probably
# because you don't have that database installed - it is ignored and the
# commit continues, perhaps ending successfully.
# Databases in this list MUST compile successfully during a commit, or the
# entire commit will fail. List the databases your application will actually
# be using to ensure your updates to that database work properly.
# This must be a list; example: ['postgres','sqlite']
required_dbs=[]
# When creating new change scripts, Migrate will stamp the new script with
# a version number. By default this is latest_version + 1. You can set this
# to 'true' to tell Migrate to use the UTC timestamp instead.
use_timestamp_numbering=False

View File

@@ -0,0 +1,54 @@
from sqlalchemy import Table, Column, Integer, Unicode, Boolean, MetaData, ForeignKey, Float, Index
meta = MetaData()
user = Table(
"users", meta,
Column("id", Integer, primary_key=True),
Column("opt_out", Boolean, default=False, nullable=False),
Column("name", Unicode(120), nullable=False, index=True, unique=True)
)
repository = Table(
"repositories", meta,
Column("id", Integer, primary_key=True),
Column("user_id", ForeignKey("users.id"), nullable=False),
Column("name", Unicode(120), nullable=False, index=True),
Column("stargazers_count", Integer, nullable=False),
Column("fork", Boolean, nullable=False),
Column("default_branch", Unicode(80), nullable=False),
Column("archived", Boolean, nullable=False),
Column("updated_at", Integer, comment="Value from GitHub API", nullable=False, index=True),
Column("created_at", Integer, comment="Value from GitHub API", nullable=False),
Column("size", Integer, nullable=False, comment="Value from GitHub API"),
Column("private", Boolean, nullable=False),
)
analyze_task = Table(
"analyze_tasks", meta,
Column("id", Integer, primary_key=True),
Column("repository_id", ForeignKey("repositories.id"), nullable=False, index=True),
Column("duration", Float, nullable=False, index=True),
Column("created_at", Integer, nullable=False, index=True),
Column("worker", Unicode(80), nullable=False, index=True),
Column("level", Integer, nullable=False),
Column("url", Unicode(200), nullable=False),
Column("improvement_absolute", Integer, nullable=False, index=True),
Column("improvement_relative", Float, nullable=False, index=True)
)
def upgrade(migrate_engine):
meta.bind = migrate_engine
meta.reflect()
user.create()
repository.create()
analyze_task.create()
def downgrade(migrate_engine):
meta.bind = migrate_engine
user.drop()
repository.drop()
analyze_task.drop()

View File

@@ -0,0 +1,24 @@
from sqlalchemy import Table, MetaData, Index
meta = MetaData()
def _get_indices(meta):
meta.reflect()
Users = Table("users", meta, autoload=True, autoload_with=meta.bind)
Repositories = Table("users", meta, autoload=True, autoload_with=meta.bind)
return [
Index("repositories_name_unique_id", Users.c.id, Repositories.c.name, unique=True)
]
def upgrade(migrate_engine):
meta.bind = migrate_engine
for idx in _get_indices(meta):
idx.create()
def downgrade(migrate_engine):
meta.bind = migrate_engine
for idx in _get_indices(meta):
idx.drop()

View File

@@ -0,0 +1,26 @@
from sqlalchemy import Table, MetaData, Column, Float
meta = MetaData()
def _get_table(meta):
meta.reflect()
AnalyzeTask = Table("analyze_tasks", meta, autoload=True, autoload_with=meta.bind)
return AnalyzeTask
def _get_column():
return Column("clone_duration", Float, nullable=False, default=0, server_default="0")
def upgrade(migrate_engine):
meta.bind = migrate_engine
table = _get_table(meta)
col = _get_column()
col.create(table, populate_default=True)
def downgrade(migrate_engine):
meta.bind = migrate_engine
table = _get_table(meta)
table.c.clone_duration.drop()

View File

@@ -0,0 +1,38 @@
from sqlalchemy import Table, MetaData, Column, Integer, Index
meta = MetaData()
def _get_table(meta):
meta.reflect()
AnalyzeTask = Table("analyze_tasks", meta, autoload=True, autoload_with=meta.bind)
return AnalyzeTask
def _get_column():
return Column("status", Integer, nullable=False, default=0, server_default="2")
def _get_indices(meta):
meta.reflect()
AnalyzeTask = Table("analyze_tasks", meta, autoload=True, autoload_with=meta.bind)
return [
Index("analyze_tasks_status_idx", AnalyzeTask.c.status, unique=False)
]
def upgrade(migrate_engine):
meta.bind = migrate_engine
table = _get_table(meta)
col = _get_column()
col.create(table, populate_default=True)
for idx in _get_indices(meta):
idx.create()
def downgrade(migrate_engine):
meta.bind = migrate_engine
table = _get_table(meta)
table.c.status.drop()
for idx in _get_indices(meta):
idx.drop()

View File