My application uses Postgresql
.
I would need to remove all rows from a set of tables (table1
to table4
) and restart the id
with one command from a rb file.
In the Postgresql documentation I found that TRUNCATE with RESTART IDENTITY would do the job as follows:
TRUNCATE table1, table2, table3, table4 RESTART IDENTITY;
According to How to restart id counting on a table in PostgreSQL after deleting some previous data? at Stackoverflow, I can use the following command:
ActiveRecord::Base.connection.execute("TRUNCATE TABLE your_table_name RESTART IDENTITY")
So putting together the two documentations, would it be correct to use the following command:
ActiveRecord::Base.connection.execute("TRUNCATE table1, table2, table3, table4 RESTART IDENTITY")
considering that in the API dock documentation the connection
method is reported as deprecated or moved?.