· 6 years ago · Jul 21, 2019, 09:30 AM
1from bert import datasource, utils
2
3@binding.follow(validate_checksum, pipeline_type=constants.PipelineType.BOTTLE)
4def define_schema():
5 import os
6 import tempfile
7
8 work_queue, done_queue, ologger = utils.comm_binders(define_schema)
9
10 table_name: str = 'gaia_source'
11 sql_filepath: str = tempfile.NamedTemporaryFile().name
12
13 with open(sql_filepath, 'w') as stream:
14 stream.write(f'''
15 CREATE TABLE IF NOT EXSITS {table_name} (
16 solution_id BIGINT NOT NULL,
17 designation VARCHAR(1024) UNIQUE NOT NULL,
18 source_id BIGINT NOT NULL,
19 random_index BIGINT NOT NULL
20 )
21 ''')
22
23 with datasource.Postgres.ParseURL(os.environ['DESTINATION_URL']) as ctx:
24 cmd: str = f'''psql -c "DROP TABLE IF EXISTS {table_name};" '''
25 utils.run_command(cmd)
26
27 cmd: str = f'''psql -f {sql_filepath}'''
28 utils.run_command(cmd)
29
30 os.remove(sql_filepath)