@toren-run/core 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/migrate.js +24 -0
  2. package/package.json +1 -1
package/dist/migrate.js CHANGED
@@ -82,6 +82,30 @@ CREATE TABLE IF NOT EXISTS toren_control.telegram_state (
82
82
  id int PRIMARY KEY DEFAULT 1,
83
83
  last_update_id bigint NOT NULL DEFAULT 0
84
84
  );
85
+ CREATE TABLE IF NOT EXISTS toren_control.telegram_poll_state (
86
+ bot_key text PRIMARY KEY,
87
+ last_update_id bigint NOT NULL DEFAULT 0
88
+ );
89
+ INSERT INTO toren_control.telegram_poll_state (bot_key, last_update_id)
90
+ SELECT 'default', last_update_id FROM toren_control.telegram_state WHERE id = 1
91
+ ON CONFLICT (bot_key) DO NOTHING;
92
+ ALTER TABLE toren_control.telegram_users ADD COLUMN IF NOT EXISTS bot_key text NOT NULL DEFAULT 'default';
93
+ ALTER TABLE toren_control.telegram_invites ADD COLUMN IF NOT EXISTS bot_key text NOT NULL DEFAULT 'default';
94
+ ALTER TABLE toren_control.telegram_bindings ADD COLUMN IF NOT EXISTS bot_key text NOT NULL DEFAULT 'default';
95
+ DO $$ BEGIN
96
+ IF (SELECT count(*) FROM information_schema.key_column_usage
97
+ WHERE table_schema = 'toren_control' AND table_name = 'telegram_users'
98
+ AND constraint_name = 'telegram_users_pkey') = 1 THEN
99
+ ALTER TABLE toren_control.telegram_users DROP CONSTRAINT telegram_users_pkey;
100
+ ALTER TABLE toren_control.telegram_users ADD PRIMARY KEY (bot_key, user_id);
101
+ END IF;
102
+ IF (SELECT count(*) FROM information_schema.key_column_usage
103
+ WHERE table_schema = 'toren_control' AND table_name = 'telegram_bindings'
104
+ AND constraint_name = 'telegram_bindings_pkey') = 1 THEN
105
+ ALTER TABLE toren_control.telegram_bindings DROP CONSTRAINT telegram_bindings_pkey;
106
+ ALTER TABLE toren_control.telegram_bindings ADD PRIMARY KEY (bot_key, chat_id);
107
+ END IF;
108
+ END $$;
85
109
  CREATE TABLE IF NOT EXISTS toren_control.files (
86
110
  id text PRIMARY KEY,
87
111
  name text NOT NULL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toren-run/core",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {