diff options
Diffstat (limited to 'notes/projects/radius/sql/untitled.sql')
| -rw-r--r-- | notes/projects/radius/sql/untitled.sql | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/notes/projects/radius/sql/untitled.sql b/notes/projects/radius/sql/untitled.sql new file mode 100644 index 0000000..beacd77 --- /dev/null +++ b/notes/projects/radius/sql/untitled.sql | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | |||
| 2 | |||
| 3 | SELECT * FROM region_audit() ORDER BY poolName, regionName; | ||
| 4 | SELECT * FROM netblock_audit() ORDER BY poolName, network; | ||
| 5 | SELECT * FROM ip_audit() ORDER BY ipAddress; | ||
| 6 | |||
| 7 | |||
| 8 | CREATE TABLE IF NOT EXISTS netblock | ||
| 9 | ( | ||
| 10 | id SERIAL, | ||
| 11 | network CIDR NOT NULL UNIQUE, | ||
| 12 | poolId INTEGER NOT NULL, | ||
| 13 | regionId INTEGER, | ||
| 14 | active BOOLEAN NOT NULL DEFAULT TRUE, | ||
| 15 | description VARCHAR(32), | ||
| 16 | PRIMARY KEY ( id ), | ||
| 17 | FOREIGN KEY ( poolId ) | ||
| 18 | REFERENCES pool | ||
| 19 | ( id ), | ||
| 20 | FOREIGN KEY ( regionId ) | ||
| 21 | REFERENCES region | ||
| 22 | ( id ) | ||
| 23 | ); | ||
| 24 | |||
| 25 | |||
| 26 | CREATE TABLE IF NOT EXISTS ip | ||
| 27 | ( | ||
| 28 | address INET, | ||
| 29 | modified timestamp WITH TIME ZONE NOT NULL | ||
| 30 | DEFAULT TIMESTAMP 'epoch', | ||
| 31 | username VARCHAR(64), | ||
| 32 | acctSession VARCHAR(32), | ||
| 33 | nasId INTEGER, | ||
| 34 | PRIMARY KEY ( address ), | ||
| 35 | FOREIGN KEY ( nasId ) | ||
| 36 | REFERENCES nas | ||
| 37 | ( id ) | ||
| 38 | ); | ||
| 39 | |||
| 40 | |||
| 41 | \c syzdek | ||
| 42 | set role wheel; | ||
| 43 | drop database radius_ippool; | ||
| 44 | |||
| 45 | |||
| 46 | psql -h raddbtest.prv.acsalaska.net -f radius-roles.sql | ||
| 47 | psql -h raddbtest.prv.acsalaska.net -f ippool-database.sql | ||
| 48 | psql -h raddbtest.prv.acsalaska.net -f ippool-schema.sql \ | ||
| 49 | -f ippool-functions.sql radius_ippool | ||
| 50 | psql -h raddbtest.prv.acsalaska.net -f ippool-demo.sql radius_ippool | ||
| 51 | |||
| 52 | |||
| 53 | SELECT ip.address AS address, | ||
| 54 | region.name AS region, | ||
| 55 | pool.name AS pool, | ||
| 56 | ip.modified AS modified, | ||
| 57 | ip.username AS username, | ||
| 58 | ip.acctsession AS acctsession | ||
| 59 | FROM ip | ||
| 60 | INNER JOIN netblock | ||
| 61 | ON netblock.network >>= ip.address | ||
| 62 | INNER JOIN region | ||
| 63 | ON region.id = netblock.regionId | ||
| 64 | INNER JOIN pool | ||
| 65 | ON pool.id = netblock.poolId | ||
| 66 | INNER JOIN nas | ||
| 67 | ON nas.regionId = region.id | ||
| 68 | WHERE ip.nasId IS NULL | ||
| 69 | AND nas.name LIKE lower( 'br1.sol' ) | ||
| 70 | AND pool.name LIKE lower( 'DHCP' ) | ||
| 71 | AND netblock.active = TRUE | ||
| 72 | ORDER BY ip.modified ASC | ||
| 73 | LIMIT 1; | ||
| 74 | |||
| 75 | |||
| 76 | UPDATE ip | ||
| 77 | SET nasId = nas.id, | ||
| 78 | username = 'test1' | ||
| 79 | FROM ip | ||
| 80 | INNER JOIN netblock | ||
| 81 | ON netblock.network >>= ip.address | ||
| 82 | INNER JOIN region | ||
| 83 | ON region.id = netblock.regionId | ||
| 84 | INNER JOIN pool | ||
| 85 | ON pool.id = netblock.poolId | ||
| 86 | INNER JOIN nas | ||
| 87 | ON nas.regionId = region.id | ||
| 88 | WHERE ip.nasId IS NULL | ||
| 89 | AND nas.name LIKE 'br1.sol' | ||
| 90 | AND pool.name LIKE lower( 'DHCP' ) | ||
| 91 | AND netblock.active = TRUE | ||
| 92 | ORDER BY ip.modified ASC | ||
| 93 | LIMIT 1; | ||
| 94 | |||
| 95 | DECLARE | ||
| 96 | blah := 'test1'; | ||
| 97 | BEGIN | ||
| 98 | SELECT *, blah, FROM region; | ||
| 99 | END; | ||
| 100 | |||
| 101 | |||
| 102 | |||
| 103 | |||
| 104 | INSERT INTO foo | ||
| 105 | ( attr1, | ||
| 106 | attr2, | ||
| 107 | attr3 | ||
| 108 | ) | ||
| 109 | VALUES ( 'val1', | ||
| 110 | 'val2', | ||
| 111 | 'val3' | ||
| 112 | ); | ||
| 113 | |||
| 114 | |||
| 115 | DELETE FROM foo | ||
| 116 | WHERE attr1 like 'val1'; | ||
| 117 | |||
| 118 | |||
| 119 | UPDATE foo | ||
| 120 | SET attr1 = 'valI', | ||
| 121 | attr2 = 'valII', | ||
| 122 | attr3 = 'valIII' | ||
| 123 | WHERE attr1 like 'val1'; | ||
| 124 | |||
| 125 | |||
| 126 | |||
| 127 | |||
| 128 | |||
| 129 | |||
