Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement