From 10b228224d6af560033b11c2d3573ba2e505922f Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 28 Nov 2018 12:12:49 -0500 Subject: [PATCH] Correct PostgreSQL data format and other tweaks --- sql/PostgreSQL/0.sql | 24 +++++++++++------------ sql/PostgreSQL/1.sql | 8 ++++---- tests/cases/Database/Base.php | 6 +++++- tests/cases/Database/SeriesMiscellany.php | 7 +++---- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/sql/PostgreSQL/0.sql b/sql/PostgreSQL/0.sql index 6e6b2f1..3d940f5 100644 --- a/sql/PostgreSQL/0.sql +++ b/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( diff --git a/sql/PostgreSQL/1.sql b/sql/PostgreSQL/1.sql index 73a0c1f..1549fd5 100644 --- a/sql/PostgreSQL/1.sql +++ b/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) ); diff --git a/tests/cases/Database/Base.php b/tests/cases/Database/Base.php index 85582e7..46ce64e 100644 --- a/tests/cases/Database/Base.php +++ b/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); diff --git a/tests/cases/Database/SeriesMiscellany.php b/tests/cases/Database/SeriesMiscellany.php index 50e4ed5..0777e4e 100644 --- a/tests/cases/Database/SeriesMiscellany.php +++ b/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()); } }