From a2bc5c614f23dc97bb0aaad43f15208f397a0203 Mon Sep 17 00:00:00 2001 From: yukkop Date: Mon, 3 Feb 2025 20:17:08 +0000 Subject: [PATCH] fix(pg-from): multy inheritence --- package/postgres/pg-from/legacy_dump.sql | 168 ----------------------- package/postgres/pg-from/src/main.rs | 13 +- 2 files changed, 9 insertions(+), 172 deletions(-) delete mode 100644 package/postgres/pg-from/legacy_dump.sql diff --git a/package/postgres/pg-from/legacy_dump.sql b/package/postgres/pg-from/legacy_dump.sql deleted file mode 100644 index 2d9a7c1..0000000 --- a/package/postgres/pg-from/legacy_dump.sql +++ /dev/null @@ -1,168 +0,0 @@ --- PostgreSQL database dump generated from SQLite -CREATE SCHEMA IF NOT EXISTS legacy; - -SET client_encoding = 'UTF8'; - -CREATE TABLE legacy."promocode" ( - "promo_name" text NOT NULL, - "traffic_amount" bigint NOT NULL, - "remaining_activation" bigint NOT NULL, - "term" text, - "pool" text DEFAULT 'residential' -) INHERITS (updated_at); - -ALTER TABLE legacy."promocode" OWNER TO postgres; - -CREATE TABLE legacy."user" ( - "user_id" text NOT NULL, - "buy_num" bigint DEFAULT 0, - "sub_id" bigint, - "used_promo_list" text, - "ip_list" text, - "pool" text -) INHERITS (updated_at); - -ALTER TABLE legacy."user" OWNER TO postgres; - -CREATE TABLE legacy."price" ( - "gb_cost" bigint, - "pool" text NOT NULL DEFAULT 'residential', - "gb_cost_usd" double precision NOT NULL DEFAULT 0 -) INHERITS (updated_at); - -ALTER TABLE legacy."price" OWNER TO postgres; - -CREATE TABLE legacy."all_user" ( - "user_id" text, - "lang" text, - "invited_by" text, - "ref_balance" bigint NOT NULL DEFAULT 0, - "pers_percent" text, - "reg_date" text, - "username" text, - "email" text, - "password" text, - "role_id" bigint, - "confirmed" bigint, - "tgcode" text, - "tgcode_expires" text, - "ref_balance_usd" double precision NOT NULL DEFAULT 0 -) INHERITS (updated_at); - -ALTER TABLE legacy."all_user" OWNER TO postgres; - -CREATE UNIQUE INDEX idx_email ON legacy."all_user" ("email"); - -CREATE UNIQUE INDEX idx_username ON legacy."all_user" ("username"); - -CREATE TABLE legacy."admin_ref" ( - "value" text, - "name" text, - "number" bigint DEFAULT 0, - "user" text -) INHERITS (updated_at); - -ALTER TABLE legacy."admin_ref" OWNER TO postgres; - -CREATE TABLE legacy."disc_promocode" ( - "name" text NOT NULL, - "discount" double precision NOT NULL, - "activations" bigint NOT NULL, - "first_use" text NOT NULL, - "term" text, - "user_for" text, - "is_global" bigint DEFAULT 0 -) INHERITS (updated_at); - -ALTER TABLE legacy."disc_promocode" OWNER TO postgres; - -CREATE TABLE legacy."request" ( - "com" text, - "amount" bigint, - "user_id" text, - "username" text, - "in_id" SERIAL PRIMARY KEY -) INHERITS (updated_at); - -ALTER TABLE legacy."request" OWNER TO postgres; - -CREATE TABLE legacy."system" ( - "key" text, - "value" text -) INHERITS (updated_at); - -ALTER TABLE legacy."system" OWNER TO postgres; - -CREATE TABLE legacy."banner" ( - "name" text, - "photo_id" text, - "link" text -) INHERITS (updated_at); - -ALTER TABLE legacy."banner" OWNER TO postgres; - -CREATE TABLE legacy."subuser" ( - "sub_id" bigint, - "owner_sub_id" bigint, - "label" text -) INHERITS (updated_at); - -ALTER TABLE legacy."subuser" OWNER TO postgres; - -CREATE TABLE legacy."reseller" ( - "user_id" text, - "token" text, - "sub_id" bigint -) INHERITS (updated_at); - -ALTER TABLE legacy."reseller" OWNER TO postgres; - -CREATE TABLE legacy."available_pay" ( - "name" text, - "is_available" text -) INHERITS (updated_at); - -ALTER TABLE legacy."available_pay" OWNER TO postgres; - -CREATE TABLE legacy."payment" ( - "user_id" text NOT NULL, - "subuser_id" bigint NOT NULL, - "paid" bigint, - "order_id" text, - "amount_gb" bigint NOT NULL, - "balance_before" text NOT NULL, - "discount" text, - "service" text NOT NULL, - "date" text NOT NULL -) INHERITS (updated_at); - -ALTER TABLE legacy."payment" OWNER TO postgres; - -CREATE TABLE legacy."temp_payment" ( - "result" text, - "payment_id" text, - "merchant_id" text, - "order_id" text, - "amount" bigint -) INHERITS (updated_at); - -ALTER TABLE legacy."temp_payment" OWNER TO postgres; - -CREATE TABLE legacy."role" ( - "id" SERIAL PRIMARY KEY, - "name" text NOT NULL -) INHERITS (updated_at); - -ALTER TABLE legacy."role" OWNER TO postgres; - -CREATE TABLE legacy."promo_activations" ( - "user_id" text NOT NULL, - "promo_name" text NOT NULL, - "usage_count" bigint NOT NULL DEFAULT 0, - PRIMARY KEY ("user_id", "promo_name") -) INHERITS (updated_at); - -ALTER TABLE legacy."promo_activations" OWNER TO postgres; - -CREATE SEQUENCE legacy_request_seq START WITH 4 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; -CREATE SEQUENCE legacy_role_seq START WITH 3 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; diff --git a/package/postgres/pg-from/src/main.rs b/package/postgres/pg-from/src/main.rs index cdcab2d..4b4fcd2 100644 --- a/package/postgres/pg-from/src/main.rs +++ b/package/postgres/pg-from/src/main.rs @@ -17,7 +17,7 @@ fn print_help(program: &str) { #[derive(Debug)] struct ColumnInfo { - cid: i32, + _cid: i32, name: String, data_type: String, notnull: bool, @@ -50,7 +50,7 @@ fn generate_create_table_sql( let columns: Vec = stmt .query_map([], |row| { Ok(ColumnInfo { - cid: row.get(0)?, + _cid: row.get(0)?, name: row.get(1)?, data_type: row.get(2)?, notnull: row.get::<_, i32>(3)? != 0, @@ -168,12 +168,17 @@ fn main() -> Result<(), Box> { let output_file = &args[2]; let schema = &args[3]; - let mut inherit_clause: Option = None; + let mut inherit_clauses: Vec = Vec::new(); for arg in &args[4..] { if arg.starts_with("--inherit=") { - inherit_clause = Some(arg["--inherit=".len()..].to_string()); + inherit_clauses.push(arg["--inherit=".len()..].to_string()); } } + let inherit_clause = if inherit_clauses.is_empty() { + None + } else { + Some(inherit_clauses.join(", ")) + }; let temp_file = NamedTempFile::new()?; fs::copy(sqlite_file, temp_file.path())?;