-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Saving nodes last IPs, countin neighbour subnet nodes
- Loading branch information
Showing
7 changed files
with
104 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import "github.com/go-pg/migrations/v7" | ||
|
||
func init() { | ||
migrations.MustRegisterTx(func(db migrations.DB) error { | ||
return execSome(db, ` | ||
ALTER TABLE storjinfo.nodes | ||
ADD COLUMN last_ip inet | ||
`, ` | ||
UPDATE storjinfo.nodes | ||
SET last_ip = (kad_params->>'last_ip')::inet | ||
WHERE kad_params ? 'last_ip' | ||
`, ` | ||
CREATE FUNCTION node_last_ip_subnet(ip inet) | ||
RETURNS cidr | ||
AS | ||
$BODY$ | ||
SELECT set_masklen(ip::cidr, 24); | ||
$BODY$ | ||
LANGUAGE sql | ||
IMMUTABLE | ||
`, ` | ||
CREATE INDEX nodes__last_ip_subnet__index ON nodes (node_last_ip_subnet(last_ip)) | ||
`) | ||
}, func(db migrations.DB) error { | ||
return execSome(db, ` | ||
DROP INDEX nodes__last_ip_subnet__index | ||
`, ` | ||
DROP FUNCTION node_last_ip_subnet | ||
`, ` | ||
ALTER TABLE storjinfo.nodes | ||
DROP COLUMN last_ip | ||
`) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters