Best Way to Start database from particular number(id) + rails - ruby

Rails app + mysql db. I want to start the db on production from a particular id, what is the best way to do it.
The first that is coming to my mind is seeding. Is there any better way I am missing here?

Under Mysql2 in a rails app there's a database called 'information_schema' and it has a table called 'tables' and it has a record where the column table_schema is the name of your sql database and the column table_name is the name of your model's table. The column auto_increment is the next record number to use.
so (for example) for database "my_database" for model table "posts" to set that to start at 500 you would do the following SQL command...
UPDATE information_schema.tables SET auto_increment = 500 WHERE table_schema = 'my_database' AND table_name = 'posts';

Related

Oracle Apex application

We are doing a project on Oracle Apex for university. We have 12 tables and try to build an app for our project. When we try to add a new page for some of our tables (not all of them) we encounter this error error description.
Can someone know how to solve this issue which is really blocking us right now.
We tried everything to solve it. All of our constraints in our tables work. What we don't understand is why we can create sometimes new pages from some tables but for other it does not work.
To me, that (unfortunately) looks like bug as you don't have any impact on Apex' data dictionary tables.
If you connect as a privileged user and check what's exactly being violated, you'll see something like this.
Which table is that constraint related to? Apparently, none:
SQL> select table_name from dba_constraints where owner = 'APEX_200200' and constraint_name = 'WWV_DICTIONARY_CACHE_OBJ_IDX2';
no rows selected
Any luck with (unique) indexes, then? Yes!
SQL> select table_name from dba_indexes where owner = 'APEX_200200' and index_name = 'WWV_DICTIONARY_CACHE_OBJ_IDX2';
TABLE_NAME
------------------------------
WWV_DICTIONARY_CACHE_OBJ
Which columns are used to enforce uniqueness?
SQL> select column_name from dba_ind_columns where index_name = 'WWV_DICTIONARY_CACHE_OBJ_IDX2';
COLUMN_NAME
--------------------------------------------------------------------------------
SECURITY_GROUP_ID
OBJECT_ID
OBJECT_TYPE
SQL>
That's to get you started; you know which table you used for that page so write some more queries and you'll - hopefully - find some move info.
How to "fix" that error? I hope you won't delete or update anything on Apex' dictionary tables! Maybe you'd rather rename that table (to avoid uniqueness violation) and try to use it, with its new name, while creating the page in your application.
If a workspace contains other object types with the same name as a table, APEX data dictionary cache job, ORACLE_APEX_DICTIONARY_CACHE, fails with ORA-00001: UNIQUE CONSTRAINT (APEX_190200.WWV_DICTIONARY_CACHE_OBJ_IDX1)
Workaround: Remove the duplicate object that is not a table. You can list database objects by selecting from sys.dba_objects.
Oracle APEX 19.2 Known Issues

Raw query to set AutoIncrement to false?

The id column in the student table is an auto incrementing one.I wanted to make that to non - autoincrementing. May i know, how can i modify the below query to work as such?
DB::statement("ALTER TABLE student SET AUTO_INCREMENT=FALSE;");
the above code shows the below error.
Illuminate\Database\QueryException
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "AUTO_INCREMENT"
LINE 1: ALTER TABLE student SET AUTO_INCREMENT=FALSE;
^ (SQL: ALTER TABLE student SET AUTO_INCREMENT=FALSE;)
The correct syntax in PostgreSQL would be:
ALTER TABLE student ALTER COLUMN id DROP DEFAULT;
Where id is the serial column.
You might also want to drop the not null constraint :
ALTER TABLE student ALTER COLUMN id DROP NOT NULL;
This is an example of why posting table definitions (ddl) and Postgres version can be critical. #Zakaria is correct if the Postgres version is prior to version 10, or if version 10 or later and is still defined as serial/bigserial. However the preferred definition for version 10 and later is generated always as identity. If defined as identity you need:
alter table student alter column id drop identity.
I would not drop a not null constraint, and if it is the PK it is moot point as it will automatically be not null.

variable table name in Spring boot

I have tables like "operation_log_202001", "operation_log_202002", ...
(I know this table structure and system structure is so bad. But I have to maintain it.)
When I try to access the "user" table, I can connect to the "user" table easily because it doesn't have any variable part in the table name.
I tried to solve this problem as below.
#Query("select * from :table_name limit 20")
Flux<ReviewData> findAll(String table_name);
But the generated query is "select * from 'operation_log_202001' limit 20". I don't wanna it to append "'" to the table name.
May I ask how to solve this problem?
Create a view, you can change it in runtime and can be mapped to an entity.
Elaborate:
A Database stores informations in tables. Those informations can be aggregated into views using custom SQL-queries. Views can act like tables, and inside their aggregation-query you are able to change the query's table-names - this way the table-name is variable.
Try with database name before table name, example :
Select * from db_log.table_name limit 20;

how to add a column after another one in monetDB

I am trying to add a new column in a monetDB database and I want it positioned after a specific one. In mysql this is possible using the AFTER keyword.
ALTER TABLE myTable ADD myNewColumn VARCHAR(255) AFTER myOtherColumn
I am trying this in the mclient:
sql>ALTER TABLE dbname.table_name ADD COLUMN new_name AFTER existing_name SET DEFAULT NULL;
What I get is a syntax error:
syntax error, unexpected AFTER in: "ALTER TABLE dbname.table_name ADD COLUMN new_name AFTER"
It is true that the ALTER documentation does not specify that AFTER exists, but I am hoping that anybody knows an alternative.
The safe way is to create an new table with the columns properly ordered and move the data; you probably know this already.
However if you really cannot do that, create a view:
CREATE VIEW AS SELECT [order the columns however you want here] FROM your_table;

How to create a temporary table in ORACLE with READ ONLY access

I am using CREATE GLOBAL TEMPORARY TABLE script to create a temporary table in the oracle DB but its showing SQL Error: ORA-01031: insufficient privileges. I Want to create a temp table with Read only access. Plz help me out in this.
What we are trying to achieve is:
We have to create a table in the destination database which is always GreenPlum.
In source database(Oracle) we are getting a select query from the USER for example: "select * from ABC A join DEF D on A.Col1=D.col1" then we are creating TEMP TABLE(In case of Oracle) on top of it for example "CREATE GLOBAL TEMPORARY TABLE table101 AS (select * from ABC A join DEF D on A.Col1=D.col1)".
Then using this TEMP table we get the required information from INFORMATION_SCHEMA for example "select * from ALL_TAB_COLUMNS where table_name='table101' ".By this we will get the column_name,data_type,character_maximum_length etc information. Using this information we can get "create table Statement" using Javascript .
Then we store this Create table statement in a variable & run it in Execute Row script(Step in pentaho data integration tool) which will create the Table in the destination DB.
Problem is that we have read only access in oracle. now what to do.
NOTE: In short, we are creating a table in the destination DB using the select statement from the source DB. Means structure of the table in Dest DB depends on the select query in Source DB.
If the target database is also an oracle database then you should be able to set up a database link there to the source database and use a "CREATE TABLE AS SELECT * FROM +source table+#+database link+;"
Whoops, I just noticed that this is from 2014. Oh well, maybe it well help future inquirers.

Resources