Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A trivial Sequel database cleaner.
require 'sequel'
require 'tsort'
class TableCleaner
def initialize db, excluded_tables
@db = db
@excluded_tables = excluded_tables
end
def clean
@db.transaction do
tables_to_clean do |t|
@db[t].delete
end
end
end
private
include TSort
def tables_to_clean &block
tsort.reverse.each &block
end
def tsort_each_node &block
@db.tables.each do |t|
block.call t unless @excluded_tables.include? t
end
end
def tsort_each_child table, &block
@db.foreign_key_list(table).each do |fk|
block.call fk[:table] unless @excluded_tables.include? fk[:table]
end
end
end
# Example usage.
require 'logger'
db = Sequel.connect ARGV[0], logger: Logger.new($stderr)
cleaner = TableCleaner.new db, [:spatial_ref_sys]
cleaner.clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.