Destroys table's constraints on table's drop

1.0
Fernando Espinosa 14 years ago
parent 9cc78b4790
commit 82f11c3891

@ -149,6 +149,11 @@ class Table < Sequel::Model(:user_tables)
end
end
def before_destroy
super
delete_constraints
end
def after_destroy
super
Tag.filter(:user_id => user_id, :table_id => id).delete
@ -460,6 +465,18 @@ class Table < Sequel::Model(:user_tables)
owner.run_query(query)
end
def constraints
owner.in_database do |user_database|
table_constraints_sql = <<-SQL
SELECT constraint_name
FROM information_schema.table_constraints
WHERE table_name = ? AND constraint_name = ?
SQL
user_database.fetch(table_constraints_sql, name, 'enforce_srid_the_geom').all
end
end
private
def update_updated_at
@ -622,6 +639,14 @@ class Table < Sequel::Model(:user_tables)
end
end
def delete_constraints
owner.in_database do |user_database|
user_database.alter_table(self.name.to_sym) do
drop_constraint(:enforce_srid_the_geom)
end
end
end
def set_triggers
owner.in_database(:as => :superuser) do |user_database|
user_database.run(<<-TRIGGER

@ -310,6 +310,7 @@ describe Table do
table.destroy
user.reload
user.tables_count.should == 0
table.constraints.count.should == 0
Tag.count.should == 0
Table.count == 0
end
@ -886,4 +887,11 @@ describe Table do
table.lon_column.should == :new_longitude
end
it "should return all table's constraints" do
user = create_user
table = create_table :user_id => user.id
puts table.constraints
table.constraints.should have_at_least(1).item
table.constraints.should include({:constraint_name => 'enforce_srid_the_geom'})
end
end
Loading…
Cancel
Save