Last active
July 9, 2019 21:46
-
-
Save jbcurtin/da352d406700be3bcba0d8cf71ea1064 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bert import datasource, utils | |
@binding.follow(validate_checksum, pipeline_type=constants.PipelineType.BOTTLE) | |
def define_schema(): | |
import os | |
import tempfile | |
work_queue, done_queue, ologger = utils.comm_binders(define_schema) | |
table_name: str = 'gaia_source' | |
sql_filepath: str = tempfile.NamedTemporaryFile().name | |
with open(sql_filepath, 'w') as stream: | |
stream.write(f''' | |
CREATE TABLE IF NOT EXSITS {table_name} ( | |
solution_id BIGINT NOT NULL, | |
designation VARCHAR(1024) UNIQUE NOT NULL, | |
source_id BIGINT NOT NULL, | |
random_index BIGINT NOT NULL | |
) | |
''') | |
with datasource.Postgres.ParseURL(os.environ['DESTINATION_URL']) as ctx: | |
cmd: str = f'''psql -c "DROP TABLE IF EXISTS {table_name};" ''' | |
utils.run_command(cmd) | |
cmd: str = f'''psql -f {sql_filepath}''' | |
utils.run_command(cmd) | |
os.remove(sql_filepath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment