Skip to content

Instantly share code, notes, and snippets.

@thbar
Last active December 17, 2019 10:01
Show Gist options
  • Save thbar/0093ee54c5a61aa5a0c5a4737fc3bd45 to your computer and use it in GitHub Desktop.
Save thbar/0093ee54c5a61aa5a0c5a4737fc3bd45 to your computer and use it in GitHub Desktop.
Creating a foreign data wrapper with Postgres and Sequel
# NOTE: several improvements to be made but I'm in a VAT preparation hurry
# - use "up" and "down" to make the migration reversible
# - use Sequel methods for extension/server create
Sequel.migration do
change do
file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'vat_rates.csv'))
run 'CREATE EXTENSION file_fdw;'
run 'CREATE SERVER file_fdw_server FOREIGN DATA WRAPPER file_fdw;'
create_table(:vat_rates, foreign: 'file_fdw_server', options: {format: 'csv', header: 'true', filename: file, delimiter: ','}) do
String :month, null: false
String :bulletin, null: false
BigDecimal :usd_for_one_eur, null: false
end
# nope, you can't create an index for foreign data wrappers
# add_index :vat_rates, :month, unique: true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment