Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. from bert import datasource, utils
  2.  
  3. @binding.follow(validate_checksum, pipeline_type=constants.PipelineType.BOTTLE)
  4. def 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement