Merge branch 'TBSliver/Postgres-Index-Fix' into development

This commit is contained in:
Tom Bloor 2017-09-06 16:45:57 +01:00
commit 260cb1e752
4 changed files with 88 additions and 0 deletions

View file

@ -13,6 +13,15 @@ ALTER TABLE customers RENAME TO customers_temp;
ALTER TABLE organisations RENAME TO organisations_temp;
ALTER TABLE transactions RENAME TO transactions_temp;
ALTER TABLE users RENAME TO users_temp;
ALTER TABLE session_tokens RENAME TO session_tokens_temp;
ALTER TABLE feedback RENAME TO feedback_temp;
ALTER INDEX transactions_idx_buyer_id RENAME TO transactions_temp_idx_buyer_id;
ALTER INDEX transactions_idx_seller_id RENAME TO transactions_temp_idx_seller_id;
ALTER INDEX session_tokens_idx_user_id RENAME TO session_tokens_temp_idx_user_id;
ALTER INDEX feedback_idx_user_id RENAME TO feedback_temp_idx_user_id;
ALTER TABLE users_temp DROP CONSTRAINT users_email;
CREATE TABLE "customers" (
"id" serial NOT NULL,
@ -65,6 +74,30 @@ CREATE TABLE "users" (
);
CREATE INDEX "users_idx_entity_id" on "users" ("entity_id");
-- Recreate session table as users is changing completely
CREATE TABLE "session_tokens" (
"id" serial NOT NULL,
"token" character varying(255) NOT NULL,
"user_id" integer NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "session_tokens_token" UNIQUE ("token")
);
CREATE INDEX "session_tokens_idx_user_id" on "session_tokens" ("user_id");
-- Also recreate feedback as this also gets broken by the user_id changes
CREATE TABLE "feedback" (
"id" serial NOT NULL,
"user_id" integer NOT NULL,
"submitted_at" timestamp NOT NULL,
"feedbacktext" text NOT NULL,
"app_name" character varying(255) NOT NULL,
"package_name" character varying(255) NOT NULL,
"version_code" character varying(255) NOT NULL,
"version_number" character varying(255) NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "feedback_idx_user_id" on "feedback" ("user_id");
DROP TABLE leaderboard_values;
TRUNCATE TABLE leaderboard_sets;
@ -81,5 +114,6 @@ CREATE TABLE "leaderboard_values" (
CREATE INDEX "leaderboard_values_idx_entity_id" on "leaderboard_values" ("entity_id");
CREATE INDEX "leaderboard_values_idx_set_id" on "leaderboard_values" ("set_id");
COMMIT;

View file

@ -2,9 +2,16 @@
BEGIN;
DROP INDEX transactions_temp_idx_buyer_id;
DROP INDEX transactions_temp_idx_seller_id;
DROP INDEX session_tokens_temp_idx_user_id;
DROP INDEX feedback_temp_idx_user_id;
DROP TABLE customers_temp;
DROP TABLE organisations_temp;
DROP TABLE transactions_temp;
DROP TABLE session_tokens_temp;
DROP TABLE feedback_temp;
DROP TABLE users_temp;
DROP TABLE pending_organisations;
DROP TABLE pending_transactions;

View file

@ -86,5 +86,31 @@ CREATE TABLE users (
CREATE INDEX users_idx_entity_id02 ON users (entity_id);
CREATE UNIQUE INDEX users_email02 ON users (email);
ALTER TABLE session_tokens RENAME TO session_tokens_temp;
CREATE TABLE session_tokens (
id INTEGER PRIMARY KEY NOT NULL,
token varchar(255) NOT NULL,
user_id integer NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX session_tokens_idx_user_id02 ON session_tokens (user_id);
CREATE UNIQUE INDEX session_tokens_token02 ON session_tokens (token);
ALTER TABLE feedback RENAME TO feedback_temp;
CREATE TABLE feedback (
id INTEGER PRIMARY KEY NOT NULL,
user_id integer NOT NULL,
submitted_at datetime NOT NULL,
feedbacktext text NOT NULL,
app_name varchar(255) NOT NULL,
package_name varchar(255) NOT NULL,
version_code varchar(255) NOT NULL,
version_number varchar(255) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX feedback_idx_user_id02 ON feedback (user_id);
COMMIT;

View file

@ -15,6 +15,8 @@ schema_from_schema_loader({ naming => 'v7' }, sub {
my $transaction_rs = $schema->resultset('TransactionsTemp');
my $pending_org_rs = $schema->resultset('PendingOrganisation');
my $pending_trans_rs = $schema->resultset('PendingTransaction');
my $feedback_rs = $schema->resultset('FeedbackTemp');
my $session_token_rs = $scheme->resultset('SessionTokensTemp');
# Lookups used for converting transactions
my $org_lookup = {};
@ -108,4 +110,23 @@ schema_from_schema_loader({ naming => 'v7' }, sub {
});
}
}
for my $session_token ( $session_token_rs->all ) {
$schema->resultset('SessionToken')->create({
token => $session_token->token,
user_id => $user_lookup->{ $session_token->user_id },
});
}
for my $feedback_result ( $feedback_rs->all ) {
$schema->resultset('Feedback')->create({
user_id => $user_lookup->{ $feedback_result->user_id },
submitted_at => $feedback_result->submitted_at,
feedbacktext => $feedback_result->feedbacktext,
app_name => $feedback_result->app_name,
package_name => $feedback_result->package_name,
version_code => $feedback_result->version_code,
version_number => $feedback_result->version_number,
});
}
});