Browse Source

Correct PostgreSQL data format and other tweaks

microsub
J. King 5 years ago
parent
commit
10b228224d
  1. 24
      sql/PostgreSQL/0.sql
  2. 8
      sql/PostgreSQL/1.sql
  3. 6
      tests/cases/Database/Base.php
  4. 7
      tests/cases/Database/SeriesMiscellany.php

24
sql/PostgreSQL/0.sql

@ -31,7 +31,7 @@ create table arsse_folders(
owner text not null references arsse_users(id) on delete cascade on update cascade,
parent bigint references arsse_folders(id) on delete cascade,
name text not null,
modified timestamp(0) with time zone not null default CURRENT_TIMESTAMP, --
modified timestamp(0) without time zone not null default CURRENT_TIMESTAMP, --
unique(owner,name,parent)
);
@ -41,10 +41,10 @@ create table arsse_feeds(
title text,
favicon text,
source text,
updated timestamp(0) with time zone,
modified timestamp(0) with time zone,
next_fetch timestamp(0) with time zone,
orphaned timestamp(0) with time zone,
updated timestamp(0) without time zone,
modified timestamp(0) without time zone,
next_fetch timestamp(0) without time zone,
orphaned timestamp(0) without time zone,
etag text not null default '',
err_count bigint not null default 0,
err_msg text,
@ -59,8 +59,8 @@ create table arsse_subscriptions(
id bigserial primary key,
owner text not null references arsse_users(id) on delete cascade on update cascade,
feed bigint not null references arsse_feeds(id) on delete cascade,
added timestamp(0) with time zone not null default CURRENT_TIMESTAMP,
modified timestamp(0) with time zone not null default CURRENT_TIMESTAMP,
added timestamp(0) without time zone not null default CURRENT_TIMESTAMP,
modified timestamp(0) without time zone not null default CURRENT_TIMESTAMP,
title text,
order_type smallint not null default 0,
pinned smallint not null default 0,
@ -74,9 +74,9 @@ create table arsse_articles(
url text,
title text,
author text,
published timestamp(0) with time zone,
edited timestamp(0) with time zone,
modified timestamp(0) with time zone not null default CURRENT_TIMESTAMP,
published timestamp(0) without time zone,
edited timestamp(0) without time zone,
modified timestamp(0) without time zone not null default CURRENT_TIMESTAMP,
content text,
guid text,
url_title_hash text not null,
@ -95,14 +95,14 @@ create table arsse_marks(
subscription bigint not null references arsse_subscriptions(id) on delete cascade on update cascade,
read smallint not null default 0,
starred smallint not null default 0,
modified timestamp(0) with time zone not null default CURRENT_TIMESTAMP,
modified timestamp(0) without time zone not null default CURRENT_TIMESTAMP,
primary key(article,subscription)
);
create table arsse_editions(
id bigserial primary key,
article bigint not null references arsse_articles(id) on delete cascade,
modified timestamp(0) with time zone not null default CURRENT_TIMESTAMP
modified timestamp(0) without time zone not null default CURRENT_TIMESTAMP
);
create table arsse_categories(

8
sql/PostgreSQL/1.sql

@ -6,8 +6,8 @@
create table arsse_sessions (
id text primary key,
created timestamp(0) with time zone not null default CURRENT_TIMESTAMP,
expires timestamp(0) with time zone not null,
created timestamp(0) without time zone not null default CURRENT_TIMESTAMP,
expires timestamp(0) without time zone not null,
"user" text not null references arsse_users(id) on delete cascade on update cascade
);
@ -15,7 +15,7 @@ create table arsse_labels (
id bigserial primary key,
owner text not null references arsse_users(id) on delete cascade on update cascade,
name text not null,
modified timestamp(0) with time zone not null default CURRENT_TIMESTAMP,
modified timestamp(0) without time zone not null default CURRENT_TIMESTAMP,
unique(owner,name)
);
@ -24,7 +24,7 @@ create table arsse_label_members (
article bigint not null references arsse_articles(id) on delete cascade,
subscription bigint not null references arsse_subscriptions(id) on delete cascade,
assigned smallint not null default 1,
modified timestamp(0) with time zone not null default CURRENT_TIMESTAMP,
modified timestamp(0) without time zone not null default CURRENT_TIMESTAMP,
primary key(label,article)
);

6
tests/cases/Database/Base.php

@ -76,6 +76,7 @@ abstract class Base extends \JKingWeb\Arsse\Test\AbstractTest{
$this->markTestSkipped(static::$failureReason);
}
Arsse::$db = new Database(static::$drv);
Arsse::$db->driverSchemaUpdate();
// create a mock user manager
Arsse::$user = Phake::mock(User::class);
Phake::when(Arsse::$user)->authorize->thenReturn(true);
@ -115,7 +116,10 @@ abstract class Base extends \JKingWeb\Arsse\Test\AbstractTest{
$drv = static::$drv;
$tr = $drv->begin();
foreach ($data as $table => $info) {
$cols = implode(",", array_keys($info['columns']));
$cols = array_map(function($v) {
return '"'.str_replace('"', '""', $v).'"';
}, array_keys($info['columns']));
$cols = implode(",", $cols);
$bindings = array_values($info['columns']);
$params = implode(",", array_fill(0, sizeof($info['columns']), "?"));
$s = $drv->prepareArray("INSERT INTO $table($cols) values($params)", $bindings);

7
tests/cases/Database/SeriesMiscellany.php

@ -27,11 +27,11 @@ trait SeriesMiscellany {
}
public function testInitializeDatabase() {
$d = new Database();
$this->assertSame(Database::SCHEMA_VERSION, $d->driverSchemaVersion());
$this->assertSame(Database::SCHEMA_VERSION, Arsse::$db->driverSchemaVersion());
}
public function testManuallyInitializeDatabase() {
(static::$dbInfo->razeFunction)(static::$drv);
$d = new Database(false);
$this->assertSame(0, $d->driverSchemaVersion());
$this->assertTrue($d->driverSchemaUpdate());
@ -40,7 +40,6 @@ trait SeriesMiscellany {
}
public function testCheckCharacterSetAcceptability() {
$d = new Database();
$this->assertInternalType("bool", $d->driverCharsetAcceptable());
$this->assertInternalType("bool", Arsse::$db->driverCharsetAcceptable());
}
}

Loading…
Cancel
Save