Modified insert query for accounts
Accounts/Posts are now relational
This commit is contained in:
parent
471b011dc0
commit
d2f982c5d1
@ -269,17 +269,25 @@ func writePost(pool *pgxpool.Pool, reportpost ReportPost) {
|
||||
defer conn.Release()
|
||||
|
||||
// Insert new account if new
|
||||
_, err = conn.Exec(context.Background(), "INSERT INTO accounts (acct, avatar, bot, created_at, display_name, url) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (acct) DO NOTHING", reportpost.Account.Acct, reportpost.Account.Avatar, reportpost.Account.Bot, reportpost.Account.Created_at, reportpost.Account.Display_name, reportpost.Account.Url)
|
||||
var acctid int
|
||||
err = conn.QueryRow(context.Background(), "INSERT INTO accounts (acct, avatar, bot, created_at, display_name, url) VALUES($1, $2, $3, $4, $5, $6) ON CONFLICT(acct) DO UPDATE SET acct=EXCLUDED.acct RETURNING id", reportpost.Account.Acct, reportpost.Account.Avatar, reportpost.Account.Bot, reportpost.Account.Created_at, reportpost.Account.Display_name, reportpost.Account.Url).Scan(&acctid)
|
||||
if err != nil {
|
||||
fmt.Println("First ", err)
|
||||
fmt.Println(reportpost.Account.Acct, reportpost.Account.Avatar, reportpost.Account.Bot, reportpost.Account.Created_at, reportpost.Account.Display_name, reportpost.Account.Url)
|
||||
os.Exit(1) // For now I want this to die and learn why it failed
|
||||
return
|
||||
}
|
||||
|
||||
// Insert new post if new
|
||||
_, err = conn.Exec(context.Background(), "INSERT INTO posts (url, content, created_at, strippedcontent, posthash) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (posthash) DO NOTHING", reportpost.Url, reportpost.Content, reportpost.Created_at, reportpost.StrippedContent, reportpost.Posthash)
|
||||
if err != nil {
|
||||
_, err = conn.Exec(context.Background(), "INSERT INTO posts (url, content, created_at, strippedcontent, acct_id, posthash) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (posthash) DO NOTHING", reportpost.Url, reportpost.Content, reportpost.Created_at, reportpost.StrippedContent, acctid, reportpost.Posthash)
|
||||
if err != nil { // For now I want to know why this failed.
|
||||
fmt.Println("Second ", err)
|
||||
os.Exit(1) // For now I want this to die and learn why it failed
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Properly executed")
|
||||
|
||||
}
|
||||
|
||||
func SuspendInstance(suspendinstance ReportInstance, runninginstances *[]RunningInstance) {
|
||||
|
32
poll/tables.sql
Normal file
32
poll/tables.sql
Normal file
@ -0,0 +1,32 @@
|
||||
CREATE TABLE accounts (
|
||||
id serial NOT NULL PRIMARY KEY,
|
||||
acct VARCHAR(100) NOT NULL UNIQUE,
|
||||
avatar VARCHAR(2083) NOT NULL,
|
||||
bot boolean,
|
||||
created_at VARCHAR(100) NOT NULL,
|
||||
display_name VARCHAR(100) NOT NULL,
|
||||
url VARCHAR(2083) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE posts (
|
||||
id serial NOT NULL PRIMARY KEY,
|
||||
url VARCHAR(2083) NOT NULL,
|
||||
content text,
|
||||
strippedcontent text,
|
||||
created_at timestamptz DEFAULT NOW(),
|
||||
|
||||
acct_id int NOT NULL REFERENCES accounts (id),
|
||||
|
||||
posthash bytea UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE instances (
|
||||
id serial NOT NULL PRIMARY KEY,
|
||||
endpoint VARCHAR(2083) NOT NULL,
|
||||
autostart boolean,
|
||||
state varchar(16),
|
||||
username varchar(32),
|
||||
password varchar(32),
|
||||
|
||||
software varchar(50)
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user