-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_reports.rb
25 lines (18 loc) · 1.45 KB
/
delete_reports.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'active_record'
conn = ActiveRecord::Base.establish_connection adapter: 'sqlserver', host: "your-host", username: "your-username", password: "your-password", database: "your-database", azure: true, port: 1433, timeout: 2500000
delete_azure_report_sql = "DELETE FROM azure_billing_report where report_date > '#{(Time.now - 2.months).strftime('%Y-%m-01')}'"
delete_aws_report_sql = "DELETE FROM aws_reports where report_date > '#{(Time.now - 2.months).strftime('%Y-%m-01')}'"
delete_aws_ey_report_sql = "DELETE FROM aws_ey_reports where report_date > '#{(Time.now - 2.months).strftime('%Y-%m-01')}'"
p "Delete azure reports"
ActiveRecord::Base.connection.raw_connection.execute("Truncate table azure_billing_report_temp").do
ActiveRecord::Base.connection.raw_connection.execute(delete_azure_report_sql).do
p "Delete AwsEy reports"
ActiveRecord::Base.connection.raw_connection.execute("Truncate table aws_ey_reports_temp").do
ActiveRecord::Base.connection.raw_connection.execute(delete_aws_ey_report_sql).do
p "Delete aws reports"
ActiveRecord::Base.connection.raw_connection.execute(delete_aws_report_sql).do
#ActiveRecord::Base.connection.raw_connection.execute("Truncate table azure_billing_report_temp").do
p "Delete aws reports temp"
ActiveRecord::Base.connection.raw_connection.execute("Truncate table aws_reports_temp").do
ActiveRecord::Base.connection.raw_connection.execute("Truncate table INFRASTRUCTURE_REPORT_FINAL").do
ActiveRecord::Base.remove_connection(conn)