Esempio n. 1
0
def init(branch=dolthub_branch):
    # check if repo already exists in our cwd
    cwd = os.getcwd()
    path = os.path.join(cwd, dolthub_repo)
    if os.path.isdir(path):
        print(' [*] DoltHub Repo found in ./{}, re-initializing'.format(dolthub_repo))
        dolt = Dolt(path)
        # make sure the data isn't stale and pull new data
        print(' [*] Performing `dolt pull` to ensure repo is up to date')
        # check what branch we have
        b = Dolt.branch(dolt)[0].name
        print('   [*] Current Branch: {}'.format(b))
        # if we are not on the branch passed, then switch
        if b != branch:
            try:
                print('   [*] Checking out branch: {}'.format(branch))
                Dolt.checkout(dolt, branch=branch)
                # recheck the branch
                b = Dolt.branch(dolt)[0].name
                print('   [*] Current Branch: {}'.format(b))
            except:
                pass

        p = Dolt.pull(dolt)
        s = Dolt.status(dolt)
        
        print('   [*] Current Status: {}'.format(s))
    else:
        # clone the database from DoltHub, save it into a var to be referenced for read/write purposes
        print(' [*] Cloning DoltHub Repo: {} into ./{}'.format(dolthub_fullrepo, dolthub_repo))
        dolt = Dolt.clone(dolthub_fullrepo, branch=branch)
        b = Dolt.branch(dolt)[0].name
        print('   [*] Current Branch: {}'.format(b))
    return dolt
Esempio n. 2
0
from doltpy.cli import Dolt
from doltpy.sql import DoltSQLServerContext, ServerConfig
import sqlalchemy as sa
import os

cur_dir = os.path.dirname(os.path.realpath(__file__))
f = open(cur_dir + "/../../private/.mysql_password", "r")
mysql_password = f.read().strip("\n")

# Setup objects to represents source and target databases, start Dolt SQL Server
dolt = Dolt.clone('durst/csknow')
dssc = DoltSQLServerContext(dolt, ServerConfig())
dssc.start_server()
mysql_engine = sa.create_engine(
    '{dialect}://{user}:{password}@{host}:{port}/{database}'.format(
        dialect='mysql+mysqlconnector',
        user="******",
        password=mysql_password,
        host="localhost",
        port="3124",
        database="csknow"
    )
)

from doltpy.sql.sync import sync_schema_to_dolt, MYSQL_TO_DOLT_TYPE_MAPPING

sync_schema_to_dolt(mysql_engine,
                    dssc.engine,
                    {"players":"players", "rounds":"rounds", "ticks":"ticks", "player_at_tick":"player_at_tick", "spotted":"spotted", "weapon_fire":"weapon_fire", "kills":"kills", "hurt":"hurt", "grenades":"grenades", "flashed":"flashed", "grenade_trajectories":"grenade_trajectories", "plants":"plants", "defusals":"defusals", "explosions":"explosions"},
                    MYSQL_TO_DOLT_TYPE_MAPPINGS)